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