May I ask questions about php Resource?

Source: Internet
Author: User
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.

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.