Jump to content

Recommended Posts

Hi guys. This is my first post. I've been speed reading through the net for a few days now trying to figure out my problem. I'm relatively new to PHP so if any of my code besides my existing problem seems unorthodox that is probably why  :P

 

Okay first things first. The following code works on a hosted php4 debian server and a php5 apache server. It does not work on a hosted php5 debian server. It also does not work on my localhost WAMP server which has php5.3.

 

I don't actually get any php or mysql errors with the code - the page either never loads or says the connection has reset (in firefox3) I did however read that there was a WAMP error log and in it I get this error:

 

mysql_num_rows() expects parameter 1 to be resource, boolean given

 

its pretty simple code just a side project I've been working on. Here it is:

 

include("scripts/connect.php");

 

//Grab cookie values

$username_cookie = $_COOKIE['username'];

$password_cookie = $_COOKIE['password'];

 

//Cross check cookie values to database values

$query = "SELECT * FROM users WHERE username='$username_cookie' and password='$password_cookie'";

 

$result = mysql_query($query);

 

if (mysql_num_rows($result) != 1) { //Make sure username and password exist on the same table row

  //login here

} else {

  //welcome!

}

 

I'm sure some one will ask so I'll go ahead and say now that the connect.php file actually works without error :P

 

If you need anything else from me let me know.

 

Any and all help is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/206916-login-cookies-and-php4-vs-php5/
Share on other sites

The error means that your query failed due to an error (this is NOT the result of a query that executed but matched zero rows.)

 

If you echo mysql_error(); on the next line after the line with your mysql_query() statement, it will tell you why the query failed.

 

 

 

 

Thanks! I changed the code to look like this:

 

include("scripts/connect.php");

 

//Grab cookie values

$username_cookie = $_COOKIE['username'];

$password_cookie = $_COOKIE['password'];

 

//Cross check cookie values to database values

$query = "SELECT * FROM users WHERE username='$username_cookie' and password='$password_cookie'";

 

$result = mysql_query($query);

 

echo mysql_error();

 

if (mysql_num_rows($result) != 1) { //Make sure username and password exist on the same table row

  //login here

} else {

  //welcome!

}

 

I added the highlighted and ran it on my WAMP php5.3 and it came back:

 

The connection was reset

The connection to the server was reset while the page was loading.

 

To make sure that this wasnt an issue with file path or anything I stripped the if statement that contains the mysql_num_rows restraint and just displayed the content as if I were logged in and it displays fine in WAMP.

 

I read somewhere that connection reset could mean that my code is stuck in an infinite loop. However I'm not sure what that means entirely.

 

Hopefully this useless information helps :(

 

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.