【发布时间】:2014-10-25 15:33:39
【问题描述】:
我将= 更改为=>。不幸的是,我收到另一条错误消息:
警告:在第 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>
【问题讨论】:
标签: mysql checkbox delete-row