My UPDATE query is failing although the syntax looks fine to me (I have another update query that works fine on the same page).
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("sitename") or die(mysql_error());
$id = $_GET['id'];
if (isset($_POST['submit'])){
$b = mysql_real_escape_string(trim($_POST['body']));
//**You have an error in your SQL syntax;** --> ?
mysql_query ("UPDATE body SET body= $b WHERE id = $id") or die (mysql_error() );
// $b is fine
echo "$b";
}
How the HTML review forms are rendered..
// Puts SQL Data into an array
$q = mysql_query("SELECT * FROM vote") or die (mysql_error());
// Now we loop through the database
echo "<br />";
while ($ratings = mysql_fetch_array($q))
{
//This outputs the doctors's name
echo "Doctor's name:" . $ratings['doctor_name'] ."<br />";
//This outputs a textarea for the user to submit comments
echo "<b>Your Experience: </b>";
echo "<form method='post' action='review_doctors.php'>
<textarea name='body'></textarea>
<input type='submit' name='submit' value='Send' id='submit'/>
</form>
";
echo "<br />";
echo "<p> </p>";
}
Why am I getting a SQL syntax error whenever a comment is submitted?