未定义的索引和无效的foreach()参数php [英] undefined index and invalid foreach() argument php
问题描述
我有一个页面,其中显示用户已保存到MYSQL数据库的项目,并与复选框一起回显.我希望当用户单击此复选框并单击保存"按钮时,记录将被删除,但标题中存在错误.
I have a page which shows items which users have saved to a MYSQL database, and echos it out along with a a check box. I would like when a user clicks this check box and clicks the save button that the record will be deleted but i am met with the errors in my title.
显示假期表.
<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
delete 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)
行,我无法理解为什么它不起作用,将不胜感激.
The error is showing at the foreach($_POST['del'] as $check_value)
line and i cant understand why its not working, any help would be appreciated.
注意:未定义的索引:del in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/Ass/deleteProcess.php 在第14行
Notice: Undefined index: del in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/Ass/deleteProcess.php on line 14
警告:为中的foreach()提供了无效的参数 /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/Ass/deleteProcess.php 在第14行
Warning: Invalid argument supplied for foreach() in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/Ass/deleteProcess.php on line 14
推荐答案
您的del
复选框完全没有从表单中发布.您需要在表单中添加method="post"
.
Your del
checkboxes aren't being POSTed from the form at all. You need to add method="post"
to your form.
<form action="deleteProcess.php" method="post">
这篇关于未定义的索引和无效的foreach()参数php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!