Mr_J Posted July 21, 2011 Share Posted July 21, 2011 Hi, When I login to my database, after I added an extra field on table, I get this warning: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/pharmacz/public_html/ads/inlogger.php on line 28 So I had another look at my code and I can't see anything wrong. So I searched google and the best article I could get is http://www.php.net/manual/en/function.mysql-num-rows.php Then I see it is a FUNCTION and I do not use my statement like the example shows This is line 28: $count=mysql_num_rows($result); //Must be 1 row this is all of the code: <?php $host="localhost"; $username="my_username"; $password="my_password"; $db_name="db_name"; $tbl_name="table_name"; mysql_connect("$host", "$username", "$password")or die("cannot connect to Server"); mysql_select_db("$db_name")or die("cannot select DATABASE"); $usr=$_POST['usr']; $pw=md5($_POST['pw']); $phname=$_POST['phname'];// To protect MySQL injection $type=$_POST['type']; $usr = stripslashes($usr); $pw = stripslashes($pw); $phname = stripslashes($phname); $type = stripslashes($type); $usr = mysql_real_escape_string($usr); $pw = mysql_real_escape_string($pw); $phname = mysql_real_escape_string($phname); $type = mysql_real_escape_string($type); $sql="SELECT * FROM $tbl_name WHERE username='$usr' and password='$pw' and phname='$phname' and type='$type'"; $result=mysql_query($sql); $count=mysql_num_rows($result); //must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file session_register("usr"); session_register("pw"); session_register("phname"); session_register("type"); header("location:secure.php"); //else //echo 'Wrong Username or Password<br/><a href="javascript:history.go(-1)"><input type="button" value="Back">'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/242522-warning-mysql_num_rows/ Share on other sites More sharing options...
trq Posted July 21, 2011 Share Posted July 21, 2011 You haven't checked your query succeeded before using $result. Your query has failed. Why, most likely becuase of the fact that 'password' is a reserved word in MySql. Change your filed name and try again. You have other issues with your code: session_register has long been depricated and should no longer be used. PS: You posted this in a board with the topic of MSSQL. Your post is way off topic. Quote Link to comment https://forums.phpfreaks.com/topic/242522-warning-mysql_num_rows/#findComment-1245556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.