• 0

Solved [PHP] [Mysql] Invalid Query


Question

So I can't seem to wrap my head around this. It is pretty simple code yet won't work. The database works so that isn't the problem and the cookie matches exactly what I need it to retrieve. Any help would be appreciated.

if ( isset( $_COOKIE['EliteGen']) ) {
	$login = $_COOKIE['EliteGen']['login'];
	$auth = $_COOKIE['EliteGen']['auth'];

	$sql = "SELECT * FROM `".T_USER."` WHERE `login` = '$login' AND `auth_key` = '$auth'";
	$query = mysql_query($sql) or die('Could not connect to database or invalid query.');

	if ( mysql_num_rows($query) ) {
		$_SESSION['logged'] = 1;
	}
}

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

echo out $sql does it looks valid, is it as expected? Check mysql_error too.

Additionally, you should using mysql_real_escape_string on $login and $auth.

Link to comment
Share on other sites

  • 0

I've got a protect() function for the variables I just haven't added yet. Also, I figured out what it was. This wasn't even correct syntax to check. I had another in my config that updates if the user is logged in and the variable wasn't correct. This is solved now.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.