Page 1 of 1

getting a variable into mysql_query

Posted: Tue Oct 07, 2003 3:32 am
by adrigen
Hi,
Im just wondering how to get a variable into this following line. the variable is $CID.
As it is i get "supplied argument is not a valid MySQL-Link resource"


mysql_select_db("ce",$db);
$query2 = mysql_query("SELECT * FROM tblProducts WHERE CategoryID = %s", $CID);
if ($myrow = mysql_fetch_array($query2)) {

Any ideas? sorry im a beginner.

Posted: Tue Oct 07, 2003 4:19 am
by twigletmac
It's giving you the error because you are passing $CID as an argument to the mysql_query() function which only takes two - 1: the query itself and 2: the link resource. $CID isn't a link resource ($db is however) so it's not working.

If you change the code to:

Code: Select all

mysql_select_db('ce', $db);

$sql = "SELECT * FROM tblProducts WHERE CategoryID = $CID";
$query2 = mysql_query($sql, $db) or die(mysql_error().'<p>'.$sql.'</p>');

if ($myrow = mysql_fetch_array($query2)) {
it should remove that error.

Mac

Posted: Tue Oct 07, 2003 8:54 am
by adrigen
Thanks, I understand. (and got it to work :lol: )
Adrian