Ask the php Resource question? & Lt ;? Phpheader ("Content-type: & nbsp; text/html; & nbsp; charset = utf-8"); & nbsp; if (! Empty ($ _ POST ['username']) {& nbs ask the php Resource question?
Header ("Content-type: text/html; charset = utf-8 ");
If (! Empty ($ _ POST ['username']) {
$ Name = $ _ POST ['username'];
}
If (! Empty ($ _ POST ['pwd']) {
$ Pwd = $ _ POST ['pwd'];
}
Function sqlDql ($ name, $ pwd ){
$ Conn = mysql_connect ("localhost", "root", "root ");
If (! $ Conn ){
Die ("connection failed". mysql_error ());
}
Mysql_select_db ("test", $ conn) or die (mysql_error ());
// Set the character set
Mysql_query ("set names utf8 ");
$ SQL = "select * from zhuche ;";
$ Res = mysql_query ($ SQL, $ conn) or die (mysql_error ());
While ($ row = mysql_fetch_row ($ res )){
If ($ name = $ row [1]) {
Echo "the user name already exists.
";
Echo "back to registration page ";
// Die (mysql_free_result ($ res). "connection". mysql_close ($ conn ));
Mysql_free_result ($ res );
Mysql_close ($ conn );
Exit ();
}
}
$ Sql2 = "insert into zhuche (Username, password) values ('". $ name. "', '". $ pwd ."');";
$ Res2 = mysql_query ($ sql2, $ conn) or die (mysql_error ());
Echo"
";
Echo"Serial NumberUserPassword";
While ($ row = mysql_fetch_row ($ res )){
Echo"";
Foreach ($ row as $ key => $ val ){
Echo"-- ". $ Val ."";
}
Echo"";
}
Echo"";
Mysql_free_result ($ res );
Mysql_close ($ conn );
}
SqlDql ($ name, $ pwd );
?>
If the first while clause does not exit, why can't the following $ res get data? There is no problem with the SQL statement.
The output result is
------ Solution --------------------
Oh, I got it wrong.
However, $ res is directed to the end of the result set after while ($ row = mysql_fetch_row ($ res) {.
You need to use mysql_data_seek ($ res, 1); to wrap the result set
However, please note: even if it is bypassed, the inserted values of mysql_query ($ sql2, $ conn) are not output.