douyan1613 2012-04-26 10:17
浏览 119
已采纳

未定义的索引和无效的foreach()参数php

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.

Show holidays form.

        <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>

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;

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.

Notice: Undefined index: del in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w11026991/public_html/Ass/deleteProcess.php on line 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

  • 写回答

6条回答 默认 最新

  • dqalnwuci494308 2012-04-26 10:22
    关注

    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">

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?
  • ¥15 关于#vue.js#的问题:修改用户信息功能图片无法回显,数据库中只存了一张图片(相关搜索:字符串)
  • ¥15 texstudio的问题,
  • ¥15 spaceclaim模型变灰色
  • ¥15 求一份华为esight平台V300R009C00SPC200这个型号的api接口文档
  • ¥15 字符串比较代码的漏洞
  • ¥15 欧拉系统opt目录空间使用100%
  • ¥15 ul做导航栏格式不对怎么改?