Jump to content

Problem with checkboxes to delete multiple entries


mpsn

Recommended Posts

Hi, I want to build into my html table that populates my database table to have a column for checkboxes with a delete button that takes the user to another page to confirm the deletion by outputting a message: Are you sure you want to delete ____, followed by a for loop to see how many checked records to get its ID in order to get its appropriate name. So I have a submit button with name attribute of "delete0" and the values of the input type of checkbox is $row['ID'], for some reason, I get the notice: "Notice: Undefined index: modifyArray in C:\display.php" and modifyArray is the name I give to the checkbox attribute (please see this in my display.php below)

 

Here is my display.php

<table border="border">
        <!--NB: checkbox form for multiple delete/update/insert-->
       <form method="post" action="">
           <input type='submit' value='DELETE' name='delete0' /> 
           
<?php
    session_start();
    require 'bellSessionDisconnect.inc';
    require 'bellConnect.inc.php';

   $result=mysql_query("SELECT ID, Image, Name, Manufacturer, Price, Description, SimSupport FROM bellProducts");
    //phpinfo(); 

    //NB: print table headings
    if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table
    {
        //$counter+=1;
        print "<table border='border'>";
        print "<tr>
        <th>ID</th>
        <th>Select entries to modifiy</th> 
        <th>Image</th>
        <th>Name</th>
        <th>Manufacturer</th>
        <th>Price</th>
        <th>Description</th>
        <th>SimSupport</th>
        <th colspan='2' align='center'>Modify</th>
           </tr>";

        //NB: now output each row of records
        while($row=mysql_fetch_assoc($result))
        {
            //extract($row);
            
                print
                "<tr align='center'>
                    <td>$row[iD]</td>
                    <td><input type='checkbox' name='modifyArray[]' value='$row[iD]' /></td>
                    <td>";
                    if(!empty($row['Image']))
                    {
                        $curImage=$row['Image'];
                    }
                    else if(empty($row['Image']))
                    {
                        $curImage='fileUploadIcon.jpg';
                        //$title="please upload item image";
                    }
                       print "<img src=$curImage width='70px' height='90px' />
                    </td>
                    <td> $row[Name] </td>
                    <td> $row[Manufacturer] </td>
                    <td> $$row[Price]</td>
                    <td align='left'>$row[Description]</td>
                    <td>$row[simSupport]</td>
                    <td><a href='bellUploadForm.php?ID=$row[iD]'>UPLOAD IMAGE</a></td>
                    <td><a href='bellUpdateForm.php?ID=$row[iD]'>UPDATE</a></td>
                  </tr>";
            //}//END INNER IF
        }//END WHILE
             
  }//END BIG IF

?>

<?php           
    if(array_key_exists('delete0', $_POST))
    {
        $modifyArray=$_POST["modifyArray"];
        if(!empty($modifyArray))
        {
            header("Location: http://localhost/bellDeleteForm.php");
            exit();
        }
    }

?>
        </form>
            
</table>
    

 

I will worry about redirecting to bellDeleteForm.php to confirm the records the user wants to delete after I get this going, please help!!! Thx

Ok, I added the checked='checked' attribute for the checkbox input type, which happens to check all the entries in my html table that populates my db table, but I only want one checkbox checked (i don't know how since it's a while loop), but anyways I still get the notice: "Notice: Undefined index: modifyArray in C:\display.php". Here is my display.php again. Please help, thx.

 

display.php

<html>
<head>
<body>
<table border="border">
        <!--NB: checkbox form for multiple delete/update/insert-->
       <form method="post" action="">
           <input type='submit' value='DELETE' name='delete0' /> <!--name has suffix 0 to not get get mixed up with the submit name in update/delete php-->
           <!--<input type="submit" value="UPDATE" name="update0" />-->
<?php
    session_start();
    require 'bellSessionDisconnect.inc';
    require 'bellConnect.inc.php';

   $result=mysql_query("SELECT ID, Image, Name, Manufacturer, Price, Description, SimSupport FROM bellProducts");
    //phpinfo(); 

    //NB: print table headings
    if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table
    {
        //$counter+=1;
        print "<table border='border'>";
        print "<tr>
        <th>ID</th>
        <th>Select entries to modifiy</th> 
        <th>Image</th>
        <th>Name</th>
        <th>Manufacturer</th>
        <th>Price</th>
        <th>Description</th>
        <th>SimSupport</th>
        <th colspan='2' align='center'>Modify</th>
           </tr>";

        //NB: now output each row of records
        while($row=mysql_fetch_assoc($result))
        {
            //extract($row);
            
                print
                "<tr align='center'>
                    <td>$row[iD]</td>
                    <td><input type='checkbox' name='modifyArray[]' value='$row[iD]' checked='checked' /></td>
                    <td>";
                    if(!empty($row['Image']))
                    {
                        $curImage=$row['Image'];
                    }
                    else if(empty($row['Image']))
                    {
                        $curImage='fileUploadIcon.jpg';
                        //$title="please upload item image";
                    }
                       print "<img src=$curImage width='70px' height='90px' />
                    </td>
                    <td> $row[Name] </td>
                    <td> $row[Manufacturer] </td>
                    <td> $$row[Price]</td>
                    <td align='left'>$row[Description]</td>
                    <td>$row[simSupport]</td>
                    <td><a href='bellUploadForm.php?ID=$row[iD]'>UPLOAD IMAGE</a></td>
                    <td><a href='bellUpdateForm.php?ID=$row[iD]'>UPDATE</a></td>
                  </tr>";
            //}//END INNER IF
        }//END WHILE
             
  }//END BIG IF

?>

<?php           
    if(array_key_exists('delete0', $_POST))
    {
        $modifyArray=$_POST["modifyArray"];
        if(!empty($modifyArray))
        {
            header("Location: http://localhost/bellDeleteForm.php");
            exit();
        }
    }

?>
        </form>
            
</table>
    
</body>

</html>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.