我有一个页面显示用户已保存到 MYSQL 数据库的项目,并将其与复选框一起显示出来。我希望当用户单击此复选框并单击保存按钮时,记录将被删除,但我的标题中出现错误。
显示假期表格。
<form action="deleteProcess.php">
<?php
foreach($db->query($sql) as $row)
{
echo "<p>" . $row['title'] . "<br \>" .
$row['description'] . "<br \>" .
$row['link'] . "<br \>" .
$row['pubDate'] .
"<input type='checkbox' name='del[]' value='$row/['title'/]'/>" .
"</p>";
}
?>
<input type="submit" name="delete" value="submit" />
</form>
删除process.php
foreach($_POST['del'] as $check_value)
{
//takes session value and assigns it to a variable so that when a holiday is saved it can be distinguished by user
$user = $_SESSION['name'];
//assign the value of previous checkbox to $check
$check = $check_value;
//assign xpath query to variable $fav
$fav = "channel/item [title = \"$check\"]";
//loads instance of xml file as $holidayDoc
$holidayDoc = simplexml_load_file('holidays.xml');
//executes xpath search within holidays.xml and results stored in $favourites
$favourites = $holidayDoc->xpath($fav);
//for each element of the associative array $favourites, key will be referred to as $currentFav.
foreach($favourites as $currentFav)
{
echo "{$currentFav->link}". "<br \>";
echo "{$currentFav->title}". "<br \>";
echo "{$currentFav->description}". "<br \>";
echo "{$currentFav->pubDate} ". "<br \>";
//sql statement that states which values will be inserted into which column
$sql = "DELETE FROM `saved_holidays` (`subscriberID`, `link`, `pubDate`, `title`, `description`)
VALUES ('$user', '$currentFav->link', '$currentFav->pubDate', '$currentFav->title', '$currentFav->description')";
//connect to database then execute the sql statement.
$db->exec($sql);
//close connection to the database
$db = null;
错误显示foreach($_POST['del'] as $check_value)
在线路上,我无法理解为什么它不起作用,任何帮助将不胜感激。
注意:未定义索引:第 14 行 /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/Ass/deleteProcess.php 中的删除
警告:在第 14 行的 /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/Ass/deleteProcess.php 中为 foreach() 提供的参数无效