Mysql_num_rows () function

Source: Internet
Author: User
Mysql_num_rows () function php MySQL


The code section is as follows:
$ Username = $ _ POST ["name"];
$ Password = $ _ POST ["password"];
If ($ username & $ password)
{
If (strpos ($ username ,"")! = False) echo "invalid user name ";
Else
{
$ Con = mysql_connect ("localhost", "root", "1 ");
Mysql_select_db ("manage", $ con );
$ SQL ="
Select password
From user
Where username = '$ username'
";
$ Query = mysql_query ($ SQL );
$ Row = mysql_num_rows ($ query );
If ($ row! = 0) echo 'logon successful ';
Else
Echo 'logon failed ';
}
}
?>


Reply to discussion (solution)

$ Query = mysql_query ($ SQL) or die (mysql_error ());

$ Query = mysql_query ($ SQL) or die (mysql_error ());
What does that mean?

You can give it a try.

You can give it a try.
Q is not supported by the moderator.

The landlord's code runs under apache on the local machine, and there is no problem. The main problem is that the database connection fails, that is, it is very likely
Mysql_select_db ("manage", $ con );
This line of code has an error. The moderator provides an error message.
We recommend that you add "or die ('Get failed'. mysql_error ()" after $ res = mysql_query ($ SQL, $ con ());"

The landlord's php operations on mysql are a bit nonstandard. it is recommended that the landlord spend a little time watching the 89th tutorial on the php video tutorial of Chuanzhi podcast. It is definitely helpful for you to standardize the use of code and identify errors in the first place.

$ Query = mysql_query ($ SQL); a resource is not returned correctly.

Why can I analyze the cause of this problem only by myself?

Replace $ query = mysql_query ($ SQL) with the sentence that the moderator gave you and run it again.


Or you can use database management software such as navicat to execute the SQL statement to check whether the result is correct.

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.