Jump to content

PHP - MySQL Error?


Mko

Recommended Posts

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

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

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

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.