Mko Posted September 6, 2012 Share Posted September 6, 2012 Hey all, I'm trying to code some login system, but I get a strange error. Error: Error running query(): 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 '* FROM `loggedin` WHERE `key`='8EZ39uSpMIsdywckXKBJ6QbgT'' at line 1 Code: db_query("SELECT * FROM `loggedin` WHERE `key`='" . sanitize_input($key) . "';"); function db_query($query) { $query = @mysql_query($query) OR die("Error running query(" . $query . "): " . mysql_error()); return $query; } Any help is appreciated! Thanks, Mark Link to comment https://forums.phpfreaks.com/topic/268088-php-mysql-error/ Share on other sites More sharing options...
Jessica Posted September 6, 2012 Share Posted September 6, 2012 I don't think you should be suppressing the error. Also by assigning the result back to $query you lose your statement for debugging. Try it like this, so you can see the whole query not just the part that mysql tells you. function db_query($query) { $result = mysql_query($query) OR die("Error running query(" . $query . "): " . mysql_error()); return $result; } There doesn't seem to be any problem with the query that I see. Link to comment https://forums.phpfreaks.com/topic/268088-php-mysql-error/#findComment-1375857 Share on other sites More sharing options...
Mko Posted September 6, 2012 Author Share Posted September 6, 2012 I don't think you should be suppressing the error. Also by assigning the result back to $query you lose your statement for debugging. Try it like this, so you can see the whole query not just the part that mysql tells you. function db_query($query) { $result = mysql_query($query) OR die("Error running query(" . $query . "): " . mysql_error()); return $result; } There doesn't seem to be any problem with the query that I see. Alright thanks! However, I believe I was looking at the wrong query. Here is the one I believe is causing the problem: db_query("DELETE * FROM `loggedin` WHERE `key`='" . sanitize_input($key) . "';"); Any ideas? Link to comment https://forums.phpfreaks.com/topic/268088-php-mysql-error/#findComment-1375860 Share on other sites More sharing options...
Jessica Posted September 6, 2012 Share Posted September 6, 2012 You don't DELETE *, you just DELETE. Link to comment https://forums.phpfreaks.com/topic/268088-php-mysql-error/#findComment-1375861 Share on other sites More sharing options...
Mko Posted September 6, 2012 Author Share Posted September 6, 2012 You don't DELETE *, you just DELETE. Thanks a bunch, fixed! Link to comment https://forums.phpfreaks.com/topic/268088-php-mysql-error/#findComment-1375862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.