Pretty new at php and working on my class project.

I get this error code on my action page for my log in page plus, it does not redirect when the result is wrong. I still get into the members' area.

Code below. Thanks

"mysql_num_rows(): supplied argument is not a valid MySQL result resource"

<?php
$conn=mysql_connect("localhost","root","");
if ($conn) {
print "Connection ok. <br>";
}
$select=mysql_select_db("litto",$conn);
print "Database selected.<br>";
$sql="SELECT * FROM users WHERE username='$_POST[username] AND password='$_POST[password]'";
$results=mysql_query($sql);
if (mysql_num_rows(results)> 0) {
print "Welcome to the system";
}
else{
print "check username and password";
}
admin.php;
mysql_close($conn);
?>

Recommended Answers

All 5 Replies

Typo, in mysql query,
single quote missing (') after $_POST[username]

$sql="SELECT * FROM users WHERE username='$_POST[username] AND password='$_POST[password]'";

Thanks for the feedback. Got it working.

Today I am going to present my project. Keeping my fingers crossed for my Diploma in Web & Graphic Design.

Thanks kasim.badami. I had also been strugling with the same problem the entire day till I realised this(') was missing!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.