Rookie first contact with the MySQL database connection operation, imitate the book wrote the following code, found that can connect to the database, but the SQL statement is always not executed, the SQL statement is not a problem, in the phpMyAdmin can be executed successfully, but here is not, Ask the great God to rescue and see where the problem is.
Reply to discussion (solution)
What's wrong with the report?
What does the program output?
The program did not error, but the database did not insert successfully
What's wrong with the report?
Output error plus empty string
What does the program output?
Haha big God embarrassed, is I made a black dragon, my MySQL database does not give this user rights, so can not modify the database, after the permission is good, thank God
What does the program output?
!--? php $host = "localhost"; $userName = "Cheng"; $password = "11111111"; $dbName = "Db_student"; $connID =mysqli_connect ($host, $userName, $password, $dbName); Mysqli_query ($connID, "Set names GBK"); $query =mysqli_query ($connID, "Select Sno,sname,class,chinese,math,english from Tb_student"); $result =mysqli_query ($connID, "INSERT into Tb_student (Sno, Sname, class, Chinese, Math, 中文版) VALUES (' 012531 ', ' SBSB ' , ' 12ji ', ' 70 ', ' 70 ', ' 70 '); if ($result) {echo "OK";} Else die (' Error: '. mysql_error ()); Mysqli_close ($connID);
You try it this way
if ($result) {echo "OK";}
Else Die (' Error: '. Mysqli_error ());
Mysqli_close ($connID);