Gatsu Posted December 6, 2007 Share Posted December 6, 2007 hi, why do I get this error?Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\xampp\htdocs\t\logincfg.php on line 25Wrong Username or PasswordI use this login script and it works on my other page. <?phpsession_start();$_SESSION['id']=1;ob_start();$host="localhost"; // Host name$username="******"; // Mysql username$password="******"; // Mysql password$db_name="**********"; // Database name$tbl_name="accounts"; // Table name// Connect to server and select databse.mysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");// Define $myusername and $mypassword$myusername=$_POST['id'];$mypassword=$_POST['password'];$sql="SELECT * FROM $tbl_name WHERE login='$myusername' and pass='$mypassword'";$result=mysql_query($sql);// Mysql_num_row is counting table row$count=mysql_num_rows($result);// If result matched $myusername and $mypassword, table row must be 1 rowif($count==1){// Register $myusername, $mypassword and redirect to file "account.php"$_SESSION['id']=$myusername;session_register("id");session_register("password");header("location: account.php");}else {echo "Wrong Username or Password";}ob_end_flush();?> Line 25 = $count=mysql_num_rows($result);anybody have a solution for this? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 6, 2007 Share Posted December 6, 2007 The query failed, check the mysql_error function. Link to comment Share on other sites More sharing options...
Gatsu Posted December 6, 2007 Author Share Posted December 6, 2007 mysql_error function? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 6, 2007 Share Posted December 6, 2007 http://www.php.net/manual/en/function.mysql-error.php Link to comment Share on other sites More sharing options...
Gatsu Posted December 6, 2007 Author Share Posted December 6, 2007 maybe I use it wrong but it only added this to the error: 0: 0: Link to comment Share on other sites More sharing options...
justsomeguy Posted December 6, 2007 Share Posted December 6, 2007 $result=mysql_query($sql);if (!$result) exit (mysql_error()); Link to comment Share on other sites More sharing options...
Gatsu Posted December 6, 2007 Author Share Posted December 6, 2007 thank you very much that made me see my error =)have a great day! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.