Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: mysql_num_rows(): supplied argument is not valid

Status
Not open for further replies.

ryno3

Technical User
Feb 27, 2007
3
AU
I have created a login pagefor users. It then submits the form and checks the authenticity of the details. However when I sign in it displays
Warning: mysql_num_row(): supplied argument is not a valid MySQL result resource in

Why is this happening? On my testing server it is displayed but when I upload it displays this message. Help!
Code:
<?php
// username and password sent from admin form 
 $Username=$_POST['Username']; 
 $Password=$_POST['Password'];

$sql="SELECT * FROM users WHERE Username='$Username' and Password='$Password'";
 $result=mysql_query($sql);

// Mysql_num_row is counting table row
 $count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row

if($count==1){
// Register $username, $password and redirect to file "adminmenu.php"
 session_register("Username");
 session_register("Password"); 
 header("location: adminmenu.php");
 }
 else {
 echo "Wrong Username or Password";
 }
 ?>
 
try the following to debug. i'm assuming you have connected to your database somewhere else.

also avoid using session_register. check out the php manual for why.

Code:
<?php
// username and password sent from admin form
 $Username=$_POST['Username'];
 $Password=$_POST['Password'];

$sql="SELECT * FROM users WHERE Username='$Username' and Password='$Password'";
 $result=mysql_query($sql) [red]or die(mysql_error())[/red];

// Mysql_num_row is counting table row
 $count=mysql_num_rows($result);
// If result matched $username and $password, table row must be 1 row

if($count==1){
// Register $username, $password and redirect to file "adminmenu.php"
 session_register("Username");
 session_register("Password");
 header("location: adminmenu.php");
 }
 else {
 echo "Wrong Username or Password";
 }
 ?>
 
Yes I have a connection to the database. I now says
Parse error: syntax error, unexpected T_VARIABLE
the name of the field in the login form is Username and Password. The fields in the database are username and password. I do not understand??
 
you need to make sure that the select statement is behaving as expected - try this:

Code:
<?php
// username and password sent from admin form 
 $Username=$_POST['Username']; 
 $Password=$_POST['Password'];

$sql="SELECT * FROM users WHERE Username='$Username' and Password='$Password'";
 $result=mysql_query($sql);
echo $sql;
exit;

You should see the select statement output, and it should actually show the values you are entering. eg SELECT * FROM users WHERE Username ='JoeBloggs' AND Password ='password'

You need to make sure they exist in the database.

what line is the expected T_VARIABLE pointing to?

'When all else fails.......read the manual'
 
password is a reserved word in mysql. if you want to use it as a column name you must use backticks.

Code:
$sql="SELECT * FROM users WHERE Username='$Username' and [red]`[/red]Password[red]`[/red]='$Password'";
 
line 4 is the prob. Tried it all. I have no idea??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top