是否可以在mysql_fetch_array()
循环中执行UPDATE?像这样:
$query = "SELECT * FROM inbox";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result) or die(mysql_error())){
echo "<div>";
echo "<form method='POST'>";
echo "<h1>".$row['link']."</h1>";
echo "<h3>".$row['tittle']."</h3> na";
echo "<input type='text' name='tittle'>";
echo "<h3>".$row['content']."</h3>";
echo "<textarea name='content'></textarea>";
echo "<input type='submit' name='".$row['link']."' value='Change'>";
echo "</form>";
echo "</div>";
$tit = $_POST['tittle'];
$ten = $_POST['content'];
$link = $row['link'];
if (isset($_POST[$link])) { mysql_query("UPDATE inbox SET tittle='$tit' content='$ten' WHERE link='$link'");}
}
它必须在mysql_fetch_array()中进行更新,因为我想改变那些内容。
答案 0 :(得分:0)
语法错误,因为值应为,
分隔符:
if (isset($_POST[$link])) {
mysql_query("
UPDATE inbox SET tittle='$tit',
content='$ten'
WHERE link='$link'
");}
您应take a look at the mysqli class处理未来的查询。它就像您当前的方法一样简单,但更安全且不已弃用。