JavaScript-why is my PHP and MySQL not linked successfully?

Source: Internet
Author: User
Keywords Php mysql javascript
Today through PHP to make a registration system, but now PHP can not link to the database, the solution is why

This is the HTML code of the registration page

This is the link database, detection, insert PHP file

if (Isset ($_post["submit") && $_post["submit"] = = "Register") {$user = $_post["username"];      $PSW = $_post["password"];      $PSW _confirm = $_post["Confirm"]; if ($user = = "" | | $PSW = = "" | |      $PSW _confirm = = "") {echo "";   } else {if ($PSW = = $psw _confirm) {mysql_connect ("localhost", "root", "Qwepoi");  Connect database mysql_select_db ("Footballmanager"); Select Database mysql_query ("Set names ' GdK '"); Set Character Set $sql = "Select username from users where username = ' $_post[username] '";    SQL statement $result = mysql_query ($sql); Execute SQL statement $num = mysql_num_rows ($result);              Count the number of rows affected by the execution result if ($num)//If the user {echo "is already present; } else//does not exist the current registered user name {$sql _insert = "INSERT INTO users (username,password,p            hone,address) VALUES (' $_post[username] ', ' $_post[password ', ', ', ') ';      $res _insert = mysql_query ($sql _insert);                  $num _insert = mysql_num_rows ($res _insert);                  if ($res _insert) {echo "";                  } else {echo "";          }}} else {echo "";  }}} else {echo "";   }

?>

Database password, name, table name is correct, but always can not link to the library, which step is the problem?

Reply content:

Today through PHP to make a registration system, but now PHP can not link to the database, the solution is why

This is the HTML code of the registration page

This is the link database, detection, insert PHP file

if (Isset ($_post["submit") && $_post["submit"] = = "Register") {$user = $_post["username"];      $PSW = $_post["password"];      $PSW _confirm = $_post["Confirm"]; if ($user = = "" | | $PSW = = "" | |      $PSW _confirm = = "") {echo "";   } else {if ($PSW = = $psw _confirm) {mysql_connect ("localhost", "root", "Qwepoi");  Connect database mysql_select_db ("Footballmanager"); Select Database mysql_query ("Set names ' GdK '"); Set Character Set $sql = "Select username from users where username = ' $_post[username] '";    SQL statement $result = mysql_query ($sql); Execute SQL statement $num = mysql_num_rows ($result);              Count the number of rows affected by the execution result if ($num)//If the user {echo "is already present; } else//does not exist the current registered user name {$sql _insert = "INSERT INTO users (username,password,p            hone,address) VALUES (' $_post[username] ', ' $_post[password ', ', ', ') ';      $res _insert = mysql_query ($sql _insert);                  $num _insert = mysql_num_rows ($res _insert);                  if ($res _insert) {echo "";                  } else {echo "";          }}} else {echo "";  }}} else {echo "";   }

?>

Database password, name, table name is correct, but always can not link to the library, which step is the problem?

There's a little problem with your MySQL operation.

...省略//你需要保存$conn这个连接句柄,以备后用$conn = mysql_connect("localhost","root","qwepoi");   //连接数据库  mysql_select_db("FootballManager");  //选择数据库  mysql_query("set names 'gdk'"); //设定字符集  $sql = "select username from users where username = '$_POST[username]'"; //SQL语句 //在使用mysql_query()类的函数时,第二个参数要加上刚刚那个连接句柄$result = mysql_query($sql, $conn);    //执行SQL语句  ...省略

Additional Extras
1. If you do not even see the error, it is best to open the PHP bug log in php.ini, and set the error level, which will be able to solve the problem quickly when the development encountered errors

display_errors = Ondisplay_startup_errors = Onerror_reporting = -1log_errors = On

2. If you are using PHP7, then the MySQL extension has been removed, if it is PHP7 before the version can be used.

mysql_connect

Value to print out
Error Reporting also opens

If you are under Linux, change localhost to 127.0.0.1.

Try writing the MySQL port to the mysql_connect parameter

Use Mysqli to put the upgraded version haha

Let's see if we can connect at the command line.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.