gpt4 book ai didi

php - 警告为foreach()提供了无效的参数

转载 作者:行者123 更新时间:2023-11-29 08:03:28 28 4
gpt4 key购买 nike

我收到此错误消息,但不知道如何处理。


  警告:第31行的/home/a9083956/public_html/zundappgroesbeek/beheer/testretrievesql.html中为foreach()提供的参数无效


这是我正在使用的代码。该警告来自第31行,即foreach()行。我已经将=更改为=>以使复选框起作用,但是删除代码仍然无法起作用。

<html>
<head>
<title>Retrieve and delete 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>

最佳答案

如果未选中任何框,则不会设置$_POST['delete']。在if (isset($_POST['delete']))之前使用foreach

另外,您的SQL中有一个错误,您需要WHERE id = "$id",否则它将删除比您预期的更多的行...

关于php - 警告为foreach()提供了无效的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23182599/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com