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