Jump to content

MYSQL login error


Archadian

Recommended Posts

i have a login() function and its returning this:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check, status FROM users WHERE uname = '****' AND pass = '*****' at line 1

 

here is the login() function code:

 

function login() {

$user = $_POST['uname'];
$pass = md5($_POST['pass']);

$result = mysql_query("SELECT `uname`, `pass`, `check`, `status` FROM users WHERE uname = '$user' AND pass = '$pass'") or die(mysql_error());
$row = mysql_fetch_array($result);

	if ($_POST['uname'] == $row['uname'] && $_POST['pass'] == $row['pass']) {

		$sess = rand();
		$num = md5($sess);
		$user = $_POST['uname'];
		$pass = $_POST['pass'];
		$ip = $_SERVER['REMOTE_ADDR'];

		mysql_query("UPDATE users SET session = '$num', `check` = 'user', status = '0', user_ip = '$ip' WHERE uname = '$user' AND pass = '$pass'") or die("Could not update the login table.");

		setcookie("num", $num, time()+58060800, "/", $wbsite);
		setcookie("num", $num, time()+58060800, "/", $www);
		setcookie("user", $user, time()+58060800, "/", $wbsite);
		setcookie("user", $user, time()+58060800, "/", $www);


		unset($_POST['submit']);

		$rtitle = "Login Status";
		$restricted = "You have successfully logged in.<br><br>You will be redirected to the homepage.";

		$_SESSION['rtitle'] = $rtitle;
		$_SESSION['restricted'] = $restricted;

		echo "<META http-equiv=\"refresh\" content=\"1;URL=../index.php?modules=error\">";

	}
}

 

I have tried the ` ` around the column names in the users table, it doesn't return an error but it just stays at the login form and does nothing. Please help :(

Link to comment
https://forums.phpfreaks.com/topic/41065-mysql-login-error/
Share on other sites

bump - anyone know whats wrong with this? I tried changing it but it still fails.

 

changed it to this:

 

mysql_query("SELECT uname, pass, check, status FROM users WHERE uname = '$chkuser' AND pass = '$chkpass'") or die("Could not compare the variables.");

 

I am connection to the database because everything else works but for some reason this isn't.

Link to comment
https://forums.phpfreaks.com/topic/41065-mysql-login-error/#findComment-199257
Share on other sites

here's the error again:

 


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check, int(status) FROM users WHERE uname = '*****' AND pass = '****' at line 1

 

and here's the code giving the error:

 

mysql_query("SELECT uname, pass, check, status FROM users WHERE uname = '$chkuser' AND pass = '$chkpass'") or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/41065-mysql-login-error/#findComment-199387
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.