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.
getting a variable into mysql_query
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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:
it should remove that error.
Mac
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)) {Mac