I want to update a text field in my mysql database but it doesn’t change when I run the query. I’ve tried stripping special characters but it still doesn’t work.
UPDATE: It returns the following error: It gives the following error:
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 ‘datatext=’LET OP! Aantal Mate’ at line 1
Here is the data:
The HTML
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type="hidden" name="nr" value="1">
<textarea rows="20" cols="50" name="text"></textarea>
</form>
The PHP
$change_text = $_POST['text'];
$change_nr = $_POST['nr'];
if ((!empty($change_text))&&(!empty($change_nr)))
{
mysql_query("UPDATE table SET datatext='$change_text' WHERE datanr='$change_nr'");
}
Structure MySQL (tablename = table)
datanr = int(6)
order = text utf8_general_ci
The text area is not to blame. your sql references a column name that your table doesn’t seem to have.
Your schema has
datanrandorderwhile the update query hasdatanranddatatext.Some more tips:
mysqlbut use mysqli, pdo or better yet, a good data access layer