Forum Moderators: coopster
I can successfully add the data and view it on a webpage, but I cannot figure out how to edit it.
I have read about magicquotes, htmlspecialchars, addslashes, etc, and I have tried various combinations of these without any luck.
My code currently looks like this:
$id = $_POST['id'];
$myhtml = $_POST['myhtml'];
if (!get_magic_quotes_gpc()) {
$myhtml = addslashes($myhtml);
}
$query = ("UPDATE products SET myhtml=\"$myhtml\" where id=\"$id\"");
$result = mysql_query($query);
And the error is:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'myhtml="
Can anyone help?! or advise where I might be going wrong?
$id = $_POST['id'];
$myhtml = $_POST['myhtml'];
if (!get_magic_quotes_gpc()) {
$myhtml = addslashes($myhtml);
}
$newhtml = $myhtml . "/";
$query = ("UPDATE products SET myhtml='$newhtml' where id='$id'");
$result = mysql_query($query);
But I'm afraid I'm still getting the same error.
Am I right in thinking that this problem is something to do with html characters?
I think you may need to do the following:
$query = ("UPDATE products SET myhtml='$newhtml' where id='$id'");
$result = mysql_query($query, $db);
Other than that I don't know.
$query = ("UPDATE products SET myhtml='" . $newhtml . "' where id='" . $id . "'");
I use that syntax most of the time because it aids in viewing variables through a syntax highlighting editor.
Failing that, use:
$myhtml = mysql_real_escape_string($_POST['myhtml']);
or $myhtml = mysql_escape_string($_POST['myhtml']); if your php version is below 4.3.0
(have to be careful of magic quotes when using escape string, you can end up with double quotes if it is turned on)