Jragon Posted July 22, 2010 Share Posted July 22, 2010 Hey, When i atemt to tun this srcipt i get an error: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\visualupload\login.php on line 17 My code: <?php include("getsalt.php"); require("connect.php"); $post_username = $_POST['user']; $post_password = $_POST['pass']; if (isset($post_password) && isset($post_username)){ if(strlen($post_username)>25||strlen($post_password)>25){ die('Username or password character length too long!'); }else{ //convert pass to md5 $salt = getsalt($post_username); $post_password = md5($salt.$post_password); $login = sprintf('SELECT * FROM user WHERE username=`%s` AND password = `%s`', mysql_real_escape_string($post_username), mysql_real_escape_string($post_password)); $rowcount = mysql_num_rows(mysql_query($login)); echo $rowcount; if ($rowcount == 1){ $_SESSION['user'] = $post_username; } } }else{ die('Please enter a useranme and password'); } ?> Link to comment https://forums.phpfreaks.com/topic/208533-warning-mysql_num_rows-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
Alex Posted July 22, 2010 Share Posted July 22, 2010 You're getting that error because mysql_query is returning boolean false as a result of your query failing. You need to use quotes, not back ticks. $login = sprintf("SELECT * FROM user WHERE username='%s' AND password = '%s'", mysql_real_escape_string($post_username), mysql_real_escape_string($post_password)); Link to comment https://forums.phpfreaks.com/topic/208533-warning-mysql_num_rows-expects-parameter-1-to-be-resource-boolean-given/#findComment-1089522 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.