Jump to content

Another WHERE clause problem


burtybob

Recommended Posts

This works as long as i keep it fetching the array with where userid=$c_userid

	if ($_REQUEST[killname]) {
$victim=$_REQUEST[killname];
        $killquery=mysql_query("SELECT * FROM members WHERE `userid`=$c_userid") or die(mysql_error());
$killquery=mysql_fetch_array($killquery);
$killquery=$killquery[health];
}

BUT this DOESNT work

	if ($_REQUEST[killname]) {
$victim=$_REQUEST[killname];
$killquery=mysql_query("SELECT * FROM members WHERE `displayname`=$victim") or die(mysql_error());
$killquery=mysql_fetch_array($killquery);
$killquery=$killquery[health];
}

 

Please can anyone inform me as to why the second one wont work when all i do is change the WHERE clause?

Is it something im doing rong or is there a genuine reason it tells me

faultCode0faultStringWarning:mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vol4/byethost7.com/b7_568567/lealtatest.22web.net/htdocs/Source code/kill.php on line 161

 

line 161 is the fetch array bit.

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/75818-another-where-clause-problem/
Share on other sites

I assume $victim is a string? You must quote strings in your query. I assume $c_userid is a number, which do not need to be quoted. Try:

 

$killquery=mysql_query("SELECT * FROM members WHERE `displayname`='$victim'") or die(mysql_error());

Why use the same variable in difrent ways $killquery

$killquery=mysql_fetch_array($killquery);

$killquery=$killquery[health];

 

Used as a query

used as a result

used as a value

 

This can cause confusion later.

 

I read somewhere on this forum that some other people managed to use this way also it makes sense to me as im using one variable name instead of 4 different ones :)

 

I tried with the quotes and

faultCode0faultStringWarning:mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/vol4/byethost7.com/b7_568567/lealtatest.22web.net/htdocs/Source code/kill.php on line 161

is the result still but the die is not telling me any problems???

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.