Mysql_num_rows () function

Source: Internet
Author: User
PHP MySQL


Here is the Code section:
$username =$_post["name"];
$password =$_post["Password"];
if ($username && $password)
{
if (Strpos ($username, "")!==false) echo "User name is illegal";
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 ' login succeeded ';
Else
Echo ' Login 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'll find out if you try.

You'll find out if you try.
Moderator can give a Q not, good advice.

Landlord code in the native Apache run, there is no problem. Landlord's problem should be connected to the database failure, which is likely
mysql_select_db ("Manage", $con);
There is an error in this line of code. The moderator's practice is to provide error messages.
It is recommended that $res=mysql_query ($sql, $con) Add "or Die (' Get failed '). Mysql_error ());"

The landlord's PHP operation MySQL practice a bit irregular, it is recommended that the landlord spend a little time to see the Preach Wisdom Podcast PHP video tutorial 89th. It's great for you to use your code for the first time and find a mistake.

$query =mysql_query ($sql); There is no correct return of a resource

As for why we can only analyze the moderator's practice is to help you analyze the cause of the problem

Put you $query =mysql_query ($sql); Replace it with the one that the moderator gave you run it again try


Or you can use the database management software such as navicat the SQL statements in the inside to see if the results can be correctly found.

  • 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.