mydownfall00 Posted July 18, 2013 Share Posted July 18, 2013 I keep running into this problem on a few of my scripts now. I am putting together a signup and login form. (i know basic stuff). I have managed to create the signup and it is inserting and displaying information from my database and table. I can successfully connect as well. The warning that I am getting is : Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/content/80/11355280/html/login.php on line 30 Line 30 is BOLD mysql_connect("$host", "$username", "$password");mysql_select_db("$db_name"); $wcdname=mysql_real_escape_string($_POST['wcdname']); $pword=mysql_real_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE username='$wcdname' and password='$pword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("wcdname"); session_register("pword"); (line 30) header("location:login_complete.html"); } else { echo "Wrong Username or Password"; } ?> If I change anything on line 30 It gives me the same warning but jumps back to line 26. It is displaying the ELSE echo for Wrong Username and Password. However the username and password is correct. I am having the same problem on a few other scripts I am trying. I have also had a problem with the way I was connecting. Im not sure if its best to define the variables or to just make a connection without them. I dont know if that could be the reason I am getting an error as well. I am registered through godaddy. Thank you if you can help me, sorry for being a noob. Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
fastsol Posted July 18, 2013 Share Posted July 18, 2013 Where do you get the value for $tbl_name in the query? Change this line $result=mysql_query($sql); To this and see what the error tells you. $result=mysql_query($sql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441164 Share on other sites More sharing options...
mydownfall00 Posted July 18, 2013 Author Share Posted July 18, 2013 Hey, thanks for the quick response. Okay for the tbl_name it was a variable defined before the code I put on here. Here let me re-show it $db_name="wcdmembers"; $tbl_name="members"; mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); $wcdname=mysql_real_escape_string($_POST['wcdname']); $pword=mysql_real_escape_string($_POST['pword']); $sql="SELECT * FROM $tbl_name WHERE username='$wcdname' and password='$pword'"; $result=mysql_query($sql) or die(mysql_error()); $count=mysql_num_rows($result); if($count==1){ session_register("wcdname"); session_register("pword"); (line 30) header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> I have my connection before the dbname. This is with the code you just told me to add which is giving me a this error : Unknown column 'username' in 'where clause' On my login.html file for the form I have the username text form name as wcdname and for the password its pword. Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441166 Share on other sites More sharing options...
fastsol Posted July 18, 2013 Share Posted July 18, 2013 It's saying that the username column doesn't exist in your db (not the info in the column but the column name itself), you might have spelled it differently or with a capital, either way it's not username Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441167 Share on other sites More sharing options...
mydownfall00 Posted July 18, 2013 Author Share Posted July 18, 2013 Im pretty sure that on this line of code $sql="SELECT * FROM $tbl_name WHERE username='$wcdname' and password='$pword'"; it should read $sql="SELECT * FROM $tbl_name WHERE wcdname='$wcdname' and pword='$pword'"; because I didnt have a username or password defined anywhere. when i load this script these are the errors I get : Deprecated: Function session_register() is deprecated in /home/content/80/11355280/html/login.php on line 29Warning: session_register() [function.session-register]: Cannot send session cookie - headers already sent by (output started at /home/content/80/11355280/html/login.php:10) in/home/content/80/11355280/html/login.php on line 29Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/content/80/11355280/html/login.php:10) in/home/content/80/11355280/html/login.php on line 29Deprecated: Function session_register() is deprecated in /home/content/80/11355280/html/login.php on line 30Warning: Cannot modify header information - headers already sent by (output started at /home/content/80/11355280/html/login.php:10) in /home/content/80/11355280/html/login.php on line 31 Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441168 Share on other sites More sharing options...
mydownfall00 Posted July 18, 2013 Author Share Posted July 18, 2013 (edited) My session register isnt working I believe. Edited July 18, 2013 by mydownfall00 Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441169 Share on other sites More sharing options...
mydownfall00 Posted July 18, 2013 Author Share Posted July 18, 2013 the table i have in the db is members with these rows : id primary key auto_inc wcdname pword fname lname email phone Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441170 Share on other sites More sharing options...
Solution fastsol Posted July 18, 2013 Solution Share Posted July 18, 2013 session_register() is not a used function anymore in php, now you simply just set a session var like $_SESSION['username'] = 'whatever' The header issue is likely cause of the mysql_error being output to the screen, fix the sql error and it should go away. And yes this looks correct $sql="SELECT * FROM $tbl_name WHERE wcdname='$wcdname' and pword='$pword'"; It is also very good practice to put backticks around column and table names like this $sql="SELECT * FROM `$tbl_name` WHERE `wcdname`='$wcdname' AND `pword`='$pword'"; Plus always CAPITALIZE statements or functions names in the query like WHERE, AND, FROM, stuff like that. Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441171 Share on other sites More sharing options...
mydownfall00 Posted July 18, 2013 Author Share Posted July 18, 2013 (edited) Thank you again for your help. I think i did this correct as you said : $sql="SELECT * FROM $tbl_name WHERE wcdname='$wcdname' and pword='$pword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ $_SESSION['wcdname'] = '$wcdname' $_SESSION['pword'] = '$pword' (line 30) header("location:login_success.php"); but im still getting an error Parse error: syntax error, unexpected T_VARIABLE in /home/content/80/11355280/html/login.php on line 30 Its been awhile since I have done php so this is why im having a hard time. I can tell already that a lot is different. Im taking many notes along the way haha. Edited July 18, 2013 by mydownfall00 Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441179 Share on other sites More sharing options...
fastsol Posted July 18, 2013 Share Posted July 18, 2013 You forgot to put the ; at the end of those 2 lines Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441180 Share on other sites More sharing options...
mydownfall00 Posted July 18, 2013 Author Share Posted July 18, 2013 Wow, I missed that. I have a good checklist of stuff now to look out for. After that I have gotten it to work. Although the header tag didnt work. It gave me an error so I took it out and put in an echo to display the wcdname. Once I did that it worked and displayed the wcdname that I have in my database and works with other users. I need to look into security in my php. Quote Link to comment https://forums.phpfreaks.com/topic/280262-warning-expects-parameter-1-to-be-resource-boolean-given/#findComment-1441181 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.