Jump to content

[SOLVED] Not getting proper error message


psychohagis

Recommended Posts

I have the following query/code thing.

 

$check = @mysql_query("SELECT id, username FROM users WHERE rank='$rank'");
if (!$result)  {
$mysql_error = mysql_error();
   exit('<p>Error performing query: ' . $mysql_error . '</p>');

 

When i run it it tells me theres an "error performing query:" but then does print out the mysql_error

 

I dont understans this cos I use this sam bit of code on other pages (except with different querys)  and if theres a problem with me query it tells me what it is.

Link to comment
https://forums.phpfreaks.com/topic/44681-solved-not-getting-proper-error-message/
Share on other sites

Ok Ive changed that but now when I run the following:

 

$check = @mysql_query("SELECT id, username FROM users WHERE rank=$rank");
if (!$check)  {
$mysql_error = mysql_error();
   exit('<p>~ Error performing query: ' . $mysql_error . '</p>');
}

 

it says "Error performing query: Unknown column 'chairman' in 'where clause'"

 

which makes no sense cos i dont ask for column 'chairman'

 

This query is asking it to find $rank (which happens to be 'chairman' here) in column rank

Well for a start you should never use the suppression sign @ - its bad coding.

i dont understand why you are making this so long winded.

Try this though:

$check = mysql_query("SELECT id, username FROM users WHERE rank='{$rank}'") or die("<p>Error performing query: " . mysql_error() . "</p>");

^^ does the same as

$check = @mysql_query("SELECT id, username FROM users WHERE rank='$rank'");
if (!$result)  {
$mysql_error = mysql_error();
   exit('<p>Error performing query: ' . $mysql_error . '</p>');

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.