Possible Duplicate:
How to include a PHP variable inside a MySQL insert statement
i want to select the Category ID of a Wordpress Category by its name. The weird thing is, that if i define the Category manually, it all works perfectly.
The echo command gives me the category Name and at the end i get the Category ID in the Variable $catid.
If however i send it through a form, the echo command gives me the exact same Category Name as it does when defined manually, but the MySQL-Command just doesn't work, meaning the $catid variable stays empty.
Does anybody here have an idea, as i just can't get my head around why it works when defined directly but not when the exact same string is Posted through a form. The Code example below is part of my code with the $category Variable being passed through a form. If i were to uncomment the manual variable and comment the post variable it would all work.
// $category = "Manual"; // manually defined
$category = $_POST['category']; //defined through a form
echo $category;
$connect = mysql_connect(localhost,abc,def);
if (!$connect) {
die('Could not connect: '.mysql_error());
}
mysql_select_db("abc");
$queryresult = mysql_query("SELECT * FROM `wp_terms` WHERE `name`='$category' LIMIT 0,1");
while($row = mysql_fetch_array( $queryresult )) {
$catid = $row[term_id];
}