想让我的用户能够删除一个mysql行
我改变了=
to =>
。 不幸的是我收到另一个错误信息
警告:在第31行的/home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html中为foreach()提供的无效参数
我得到一个PHP错误消息。 我究竟做错了什么?
第31行的/home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html中解析错误:语法错误,意外的'=',期待')'
我的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");
}
请注意改变=
to =>
。
有关=>运算符的更多信息,请在这里查看相关的文章。
链接地址: http://www.djcxy.com/p/58185.html