我正在嘗試更新以使用以下代碼更新我的數據。在UPDATE查詢中可能有問題,但我檢查了語法,修改了它,但仍然無法正常工作。請幫忙。
form.php的更新查詢不工作php + mysql
<?php
require_once 'conn.php';
$var = $_GET['q'];
$varmod = 'tid="'.$var.'"';
$query = "SELECT * FROM temptable WHERE $varmod";
$result = mysql_query($query, $db) or die(mysql_error($db));
while ($row = mysql_fetch_assoc($result)) {
$head = $row['thead'];
$text = $row['ttext'];
echo "<div id='main'>";
echo "<form action='show.php?q=".$row['tid']."' method='POST'>";
echo "<textarea name='thead' id='thead'>$head</textarea><br>";
echo "<textarea name='ttext' >$text</textarea><br>";
echo "<input type='submit' value='Update' /></form></div>";
}
?>
show.php
<?php
$title = $_POST['thead'];
$text = $_POST['ttext'];
$date = date("Y-m-d");
require_once 'conn.php';
if(isset($title)){
if (isset($_GET['q'])) {
$temp = $_GET['q'];
$query = "UPDATE temptable SET thead=\"$title\" AND ttext=\"$text\" WHERE tid=\"$temp\"";
}
else{
$query= "INSERT INTO temptable
(thead, ttext, tdate)
VALUES (\"$title\", \"$text\", \"$date\")";
}
$result = mysql_query($query, $db) or die(mysql_error($db));
}
好INSERT查詢工作良好。
你會得到任何錯誤代碼? –
你的查詢應該是這樣的:'UPDATE temptable SET thead = \「$ title \」,ttext = \「$ text \」WHERE tid = \「$ temp \」「'so .. replace」and「with comma .. – Hardy
-Phoenix Wright語音 - [注入!](http://xkcd.com/327/) –