Javascript-Why is there no connection between my php and MySQL successful?

Source: Internet
Author: User
Tags php error php error log
Today, I used php to create a registration system, but now php cannot be linked to the database. The reason is why this is the HTML code {code...} on the registration page ...} this is the PHP file & amp; lt ;? Php {code ...}? & Amp; gt; Database Password, name, table name... today, a registration system is built through php, but now php cannot be linked to the database. Why?

This is the HTML code of the registration page.

 

This is the PHP file for linking database, detection, and insert.

If (isset ($ _ POST ["Submit"]) & $ _ POST ["Submit"] = "register ") {$ user = $ _ POST ["username"]; $ psw = $ _ POST ["password"]; $ psw_confirm = $ _ POST ["confirm"]; if ($ user = "" | $ psw = "" | $ psw_confirm = "") {echo "script" alert ('check the information integrity! '); History. go (-1); script ";} else {if ($ psw = $ psw_confirm) {mysql_connect (" localhost "," root "," qwepoi "); // connect to the database mysql_select_db ("FootballManager"); // select the database mysql_query ("set names 'gdk '"); // set the character set $ SQL = "select username from users where username = '$ _ POST [username]'"; // SQL statement $ result = mysql_query ($ SQL ); // execute the SQL statement $ num = mysql_num_rows ($ result); // count the number of rows affected by the execution result if ($ num) // if the user {echo "scr ERT ('user name already exists '); history. go (-1); script ";} else // The Name Of The currently registered user does not exist {$ SQL _insert =" insert into users (username, password, phone, address) values ('$ _ POST [username]', '$ _ POST [password]', ', '')"; $ res_insert = mysql_query ($ SQL _insert ); // $ num_insert = mysql_num_rows ($ res_insert); if ($ res_insert) {echo "script" alert ('registration successful! '); History. go (-1); script ";} else {echo" script alert ('the system is busy, please wait! '); History. go (-1); script ";}}} else {echo" script alert ('inconsistent passwords! '); History. go (-1); script ";}}} else {echo" script "alert ('submission failed! '); History. go (-1); script ";}

?>

The Database Password, name, and table names are correct, but they cannot be linked to the library. What is the problem?

Reply content:

Today, I used php to create a registration system, but now php cannot be linked to the database. Why?

This is the HTML code of the registration page.

 

This is the PHP file for linking database, detection, and insert.

If (isset ($ _ POST ["Submit"]) & $ _ POST ["Submit"] = "register ") {$ user = $ _ POST ["username"]; $ psw = $ _ POST ["password"]; $ psw_confirm = $ _ POST ["confirm"]; if ($ user = "" | $ psw = "" | $ psw_confirm = "") {echo "script" alert ('check the information integrity! '); History. go (-1); script ";} else {if ($ psw = $ psw_confirm) {mysql_connect (" localhost "," root "," qwepoi "); // connect to the database mysql_select_db ("FootballManager"); // select the database mysql_query ("set names 'gdk '"); // set the character set $ SQL = "select username from users where username = '$ _ POST [username]'"; // SQL statement $ result = mysql_query ($ SQL ); // execute the SQL statement $ num = mysql_num_rows ($ result); // count the number of rows affected by the execution result if ($ num) // if the user {echo "scr ERT ('user name already exists '); history. go (-1); script ";} else // The Name Of The currently registered user does not exist {$ SQL _insert =" insert into users (username, password, phone, address) values ('$ _ POST [username]', '$ _ POST [password]', ', '')"; $ res_insert = mysql_query ($ SQL _insert ); // $ num_insert = mysql_num_rows ($ res_insert); if ($ res_insert) {echo "script" alert ('registration successful! '); History. go (-1); script ";} else {echo" script alert ('the system is busy, please wait! '); History. go (-1); script ";}}} else {echo" script alert ('inconsistent passwords! '); History. go (-1); script ";}}} else {echo" script "alert ('submission failed! '); History. go (-1); script ";}

?>

The Database Password, name, and table names are correct, but they cannot be linked to the library. What is the problem?

Your mysql operations have some minor problems.

... Omit // you need to save the $ conn connection handle for later use $ conn = mysql_connect ("localhost", "root", "qwepoi "); // connect to the database mysql_select_db ("FootballManager"); // select the database mysql_query ("set names 'gdk '"); // set the character set $ SQL = "select username from users where username = '$ _ POST [username]'"; // SQL statement // use mysql_query () class function, add the connection handle $ result = mysql_query ($ SQL, $ conn) to the second parameter; // execute the SQL statement... omitted

Additional
1. If you cannot even see the error, it is best to enable the php Error Log in php. ini and set the error level, which can quickly solve the problem when development encounters errors in the future.

display_errors = Ondisplay_startup_errors = Onerror_reporting = -1log_errors = On

2. If you are using php7, the mysql extension has been removed and can be used in versions earlier than php7.

mysql_connect

The value is printed out.
The error report is also opened.

In linux, replace localhost with 127.0.0.1.

Try writing the mysql port to the mysql_connect Parameter

Use mysqli to upgrade the version haha

First, check whether the connection can be established under 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.