What I want is to update my database table by selecting the row by index number and updating the answer field on that row.
This is my form's select; it puts the index id to the option value. Also there is a textarea with the name "answer".
<select name="indexno" style="width:150px">
<option selected="selected"> </option>
<?php
require('dbconnect.php');
$query = mysql_query("SELECT * FROM mytable WHERE answer = '' ");
while($result = mysql_fetch_array($query))
{
echo "<option " . "value='" . $result['index'] . "'>";
echo $result['index'];
echo "</option>";
}
?>
</select>
This is the PHP code:
$indexno = $_POST['indexno'];
$answer = $_POST['answer'];
$date = gmdate("Y-m-d\TH:i:s\Z");
$query = "UPDATE mytable
SET answerfield = '$answer',
date = '$date'
WHERE index = '$indexno'";
$link = mysql_query($query);
However, it is not working; the error message 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 'index = '2'' at line 1
Try
WHERE `index` = '$indexno'";
精彩评论