PHP beginners for help

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

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.