我将 =
更改为 =>
。不幸的是我收到另一条错误消息:
<小时/>Warning: Invalid argument supplied for foreach() in /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html on line 31
我收到一条 php 错误消息。我做错了什么?
Parse error: syntax error, unexpected '=', expecting ')' in /home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html on line 31
我的 html 看起来像这样:
<html>
<head>
<title>Retrieve data from database </title>
</head>
<body>
<?php
// Connect to database server
mysql_connect("mysql7.000webhost.com", "a9083956_test", "sesam") or die (mysql_error ());
// Select database
mysql_select_db("a9083956_test") or die(mysql_error());
// SQL query
$strSQL = "SELECT * FROM forum_question";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
// Loop the recordset $rs
// Each row will be made into an array ($row) using mysql_fetch_array
while($row = mysql_fetch_array($rs)) {
// Write the value of the column FirstName (which is now in the array $row)
echo '<input name="delete['.$row['id'].']" type="checkbox">';
echo $row['topic']. " " .$row['name']. " " .$row['datetime'] . "<br />";
}
$delete = $_POST['delete'];
foreach($delete as $id = $value)
{
$id = mysql_real_escape_string($id);
mysql_query("DELETE FROM table_name WHERE id = $id");
}
// Close the database connection
mysql_close();
?>
</body>
</html>
最佳答案
您的问题在于 foreach 循环,其中有 $id = $value
。我怀疑你的意思是:
foreach($delete as $id => $value)
{
$id = mysql_real_escape_string($id);
mysql_query("DELETE FROM table_name WHERE id = $id");
}
请注意将 =
更改为 =>
。
有关 => 运算符的更多信息,请查看相关帖子 here .
关于mysql - 想让我的用户能够删除 mysql 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22998760/