0

hey guys so im trying to delete a row using checkbox but i get an undefined index error = Notice: Undefined index: check in D:\Xampp\htdocs\EMS2\event.php . i think its because the checkbox is echoed(?)maybe? or is it something else that i overlooked?

<tbody class="tbody-event-list-table2">
<?php
require "connection.php";

$check = mysql_query("SELECT * FROM event") or die(mysql_error());
if(mysql_num_rows($check) > 0)
{
while($row = mysql_fetch_array($check))
{
        $id = $row['event_id'];
        $name = $row['event_name'];
        $start = $row['start'];
        $end = $row['end'];
        $venue = $row['event_venue'];

echo 
"<tr>
<td><input type='checkbox' name='check' id='check' class='check' value='$id'/><a href='' class='event-link'>$name</a></td><td>$start</td><td>$end</td><td>$venue</td>";
?>
<?php
if(isset($_POST['del_event']))
{
    if(count($_POST['check']) !=0)
    {
        $array = array("check" => $_POST['check']);
        $id = implode(',', $array['check']);
        $result = mysql_query("DELETE FROM event WHERE event_id = '$id'") or die(mysql_error());
        if($result){
        echo "<meta http-equiv=\"refresh\" content=\"0;URL=event.php\">";
        }
    }
}
?>
<?php
        echo "</tr>";
        }
    }   
    else
    {
    echo 
    "<tr>
    <td colspan='4'>There Are No Events.</td>
    </tr>";
    }
?>
</tbody>
2
Contributors
4
Replies
28
Views
3 Years
Discussion Span
Last Post by nadiam
0

This is not an error, not a warning, but merely a notice. It seems to be caused by $_POST['check'] not being defined, while your script is trying to access it. You can modify which errors are being reported by using the error_reporting() function, if you wish to not display notices, but (for example) only warnings and fatal errors. Besides using error_reporting(), you can also modify the error reporting value in your php.ini file (if I'm not mistaken).

0

did error_reporting() but nothing useful. still undefined index notice so now i don't really know what the problem is.

0

this is my code now. and now no error,warning or deletion happens/appears. im at a lost. any ideas would of great help.

 <?php
    if(isset($_POST['del_event']))
    {
     if(isset($_POST['check']) && count($_POST['check']))
     {
      $array = array("check" => $_POST['check']);
      $id = implode(',', $array['check']);
      $result = mysql_query("DELETE FROM event WHERE event_id = '$id'") or die(mysql_error());
      }
    }
  ?>

html

<div class="event-list-table2" >
<form method="post" action="event.php">
    <table class="event-table">
            <thead>
                <tr>
                    <th>Event Name</th>
                    <th>Start Event</th>
                    <th>End Event</th>
                    <th>Venue</th>
                </tr>
            </thead>
            <tbody class="tbody-event-list-table2">
                <?php
                    require "connection.php";
                    $check = mysql_query("SELECT * FROM event") or die(mysql_error());
                    if(mysql_num_rows($check) > 0)
                    {
                        while($row = mysql_fetch_array($check))
                        {
                            $id = $row['event_id'];
                            $name = $row['event_name'];
                            $start = $row['start'];
                            $end = $row['end'];
                            $venue = $row['event_venue'];

                            echo 
                            "<tr>
                                <td><input type='checkbox' name='check' id='check' class='check' value='$id'/><a href='' class='event-link' value='$id'>$name</a></td><td>$start</td><td>$end</td><td>$venue</td>";
                            echo "</tr>";
                        }
                    }   
                    else
                        {
                            echo 
                            "<tr>
                                <td colspan='4'>There Are No Events.</td>
                            </tr>";
                        }
                ?>
            </tbody>
    </table>
</form>
</div>
0

so i fixed the prob. first i had to remove "form" that was separating the buttons and the table so now "form" is wrapped around both buttons and table. second is the php coding for deletion has changed too.

<form class="buttons" method="post" action="event.php">
    <div class="button-wrap">
    <input type="button" id="add_event" name="add_event" value="Add Event"/>
    <input type="submit" id="del_event" name="del_event" value="Delete Event"/>
    <input type="submit" id="edit_event" name="edit_event" value="Edit Event">
    </div>

    <div class="event-list-table2" >
        <table class="event-table">
                <thead>
                    <tr>
                        <th>Event Name</th>
                        <th>Start Event</th>
                        <th>End Event</th>
                        <th>Venue</th>
                    </tr>
                </thead>
                <tbody class="tbody-event-list-table2">
                    <?php
                        require "connection.php";
                        $check = mysql_query("SELECT * FROM event") or die(mysql_error());
                        if(mysql_num_rows($check) > 0)
                        {
                            while($row = mysql_fetch_array($check))
                            {
                                $id = $row['event_id'];
                                $name = $row['event_name'];
                                $start = $row['start'];
                                $end = $row['end'];
                                $venue = $row['event_venue'];

                                echo 
                                "<tr>
                                    <td><input type='checkbox' name='check[]' class='check' value='$id'><a href='' class='event-link' value='$id' name='event-link'>$name</a></td><td>$start</td><td>$end</td><td>$venue</td>";
                                echo "</tr>";
                            }
                        }   
                        else
                            {
                                echo 
                                "<tr>
                                    <td colspan='4'>There Are No Events.</td>
                                </tr>";
                            }
                    ?>
                </tbody>
    <?php
        if (isset($_POST['del_event']) && isset($_POST['check']))
        {
            foreach($_POST['check'] as $del_id)
            {
                $del_id = (int)$del_id;
                $sql = mysql_query("DELETE FROM event WHERE event_id = $del_id") or die(mysql_error());
                    if($sql)
                    {
                 echo "<meta http-equiv=\"refresh\" content=\"0;URL=event.php\">";
    }
            }
        }
    ?>
        </table>
    </div>
</form>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.