Jump to content

Warning : Expects parameter 1 to be resource, boolean given.


mydownfall00
Go to solution Solved by fastsol,

Recommended Posts

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.
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 29

Warning: 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 29

Warning: 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 29

Deprecated: Function session_register() is deprecated in /home/content/80/11355280/html/login.php on line 30

Warning: 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

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

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 by mydownfall00
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.