Thadeus Posted October 9, 2010 Share Posted October 9, 2010 Hello, I am having a problem.. I get this message " Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in... " whenever i am trying to work my log in script. The script is: <?php $host="localhost"; $username="root"; $password="pass"; $db_name="webDB"; $table_name="webmembers"; mysql_connect($host, $username, $password) or die ('Unable to connect'); mysql_select_db($db_name) or die ('Error'); $uname= $_POST['uname']; $pword= $_POST['pword']; $urname= stripslashes($uname); $pword= stripslashes($pword); $uname= mysql_real_escape_string($uname); $pword= mysql_real_escape_string($pword); $sql= "SELECT * FROM '$table_name' WHERE username: '$uname' and password: '$pword'"; $result=mysql_query($sql); $count= mysql_num_rows($result); <----------- problem if ($count == 1) { session_register($uname); session_register($pword); header("location: loginsuccess.php"); } else { echo $result,$count; echo "Wrong Username and Password"; } mysql_close(); ?> and "loginsuccess.php" <?php session_start(); if(!sesssion_is_registered($uname)) { header("location: mainpage.php"); } ?> <html> <head> </head> <body> Log in Successful </body> </html> why do i get this warning? what am i doing wrong? Is there any simpler way to create a log in page but being secure as well? Thank in advance. Quote Link to comment https://forums.phpfreaks.com/topic/215503-mysql_num_rows/ Share on other sites More sharing options...
darkfreaks Posted October 9, 2010 Share Posted October 9, 2010 <?php $host="localhost"; $username="root"; $password="pass"; $db_name="webDB"; $table_name="webmembers"; $link=mysql_connect($host, $username, $password) or die ('Unable to connect'); mysql_select_db($db_name) or die ('Error'); $uname= $_POST['uname']; $pword= $_POST['pword']; $urname= stripslashes($uname); $pword= stripslashes($pword); $uname= mysql_real_escape_string($uname); $pword= mysql_real_escape_string($pword); $sql= "SELECT * FROM '$table_name' WHERE username: '$uname' and password: '$pword'"; $result=mysql_query($sql); $count= mysql_num_rows($result,$link); //fixed you need the connection or else it will fail. if ($count == 1) { session_register($uname); session_register($pword); header("location: loginsuccess.php"); } else { echo $result,$count; echo "Wrong Username and Password"; } mysql_close(); ?> Fixed you need the link when you call mysql_num_rows or else it will fail. Quote Link to comment https://forums.phpfreaks.com/topic/215503-mysql_num_rows/#findComment-1120589 Share on other sites More sharing options...
PFMaBiSmAd Posted October 9, 2010 Share Posted October 9, 2010 mysql_num_rows() does NOT accept more than one parameter. The error means that your query failed due to an error. If you had searched for that error you would have learned this and that by using some error checking logic, such as echoing mysql_error(), would tell you why it failed. Your query has a few problems in it. You have single-quotes around the table name, making it a string instead of a table name (remove the single-quotes from around the table name) and you have some semi-colons : where you should be using equal signs (change them to equal signs.) Quote Link to comment https://forums.phpfreaks.com/topic/215503-mysql_num_rows/#findComment-1120590 Share on other sites More sharing options...
Thadeus Posted October 10, 2010 Author Share Posted October 10, 2010 " Unknown column 'username' in 'where clause' " That was the error. Thank you for the mysql_error() i had forgot it exists. :S The mysql_num_rows() indeed does not take more than 1 parameter. Although i have fixed the first problem another one came up. Please help me in this one as well. I got this " Fatal error: Call to undefined function sesssion_is_registered() in... " by using this code: " <?php session_start(); if(!sesssion_is_registered($uname)) { header("location: mainpage.php"); } ?> <html> <head> </head> <body> Log in Successful </body> </html> " Any suggestions please on how to fix it? Thanks again for my previous problem. Quote Link to comment https://forums.phpfreaks.com/topic/215503-mysql_num_rows/#findComment-1120688 Share on other sites More sharing options...
Pikachu2000 Posted October 10, 2010 Share Posted October 10, 2010 seSSSion_is_registered is misspelled. It is also deprecated, along with session_register. Quote Link to comment https://forums.phpfreaks.com/topic/215503-mysql_num_rows/#findComment-1120690 Share on other sites More sharing options...
gizmola Posted October 10, 2010 Share Posted October 10, 2010 " Unknown column 'username' in 'where clause' " That was the error. Thank you for the mysql_error() i had forgot it exists. :S The mysql_num_rows() indeed does not take more than 1 parameter. Although i have fixed the first problem another one came up. Please help me in this one as well. I got this " Fatal error: Call to undefined function sesssion_is_registered() in... " by using this code: " <?php session_start(); if(!sesssion_is_registered($uname)) { header("location: mainpage.php"); } ?> Log in Successful " Any suggestions please on how to fix it? Thanks again for my previous problem. This issue has nothing to do with your initial question that was answered. Please close this one and more it solved using the "Mark Solved" button at the bottom. Then make a new thread for your new problem. It helps others who search the forum for previous solutions. Quote Link to comment https://forums.phpfreaks.com/topic/215503-mysql_num_rows/#findComment-1120691 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.