I am a beginner in PHP for help. I just started a test program. The database is mydb with only one table user. the function of the program is to query the user name and customer code from mydb.
However, results cannot be returned every time you run them. I don't know why.
The code is as follows:
If (! Get_magic_quotes_gpc ())
Echo "magic_quotes_gpc is off
";
$ Uname = $ _ POST ['uname'];
$ Input_passwd =$ _ POST ['passwd'];
Echo $ uname .'
';
Echo $ input_passwd .'
';
$ Db = new mysqli ('localhost', 'root', '', 'mydb ');
If (mysqli_connect_errno ())
{
Echo 'mysqli connect error ';
Exit;
}
$ Query = "select * from mydb. user where name = $ uname ";
Echo $ query .'
';
$ Result = $ db-> query ($ query );
$ Num_result = $ result-> num_rows;
For ($ I = 0; $ I! = $ Num_result; $ I ++)
{
$ Row = $ result-> fetch_assoc ();
Echo $ row ['name']. '----------'. $ row ['passwd'].'
';
}
$ Result-> free ();
$ Db-> close ();
?>
Please help me to see if there is any problem.
Reply to discussion (solution)
For ($ I = 0; $ I <$ num_result; $ I ++)
The uname and passwd variables in the html form
The page after I enter test in uname to submit is as follows:
For ($ I = 0; $ I <$ num_result; $ I ++)
I tried it. it's useless. Not here
$ Query = "select * from mydb. user where name = '$ uname '";
Use empty ($ result) to get the null value. does this mean no data is found. However, my table is not empty!
Is the table user content
$ Query = "select * from mydb. user where name = '$ uname '";
Er, thank you very much.