mpsn Posted June 1, 2011 Share Posted June 1, 2011 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 Link to comment https://forums.phpfreaks.com/topic/238151-problem-with-checkboxes-to-delete-multiple-entries/ Share on other sites More sharing options...
requinix Posted June 1, 2011 Share Posted June 1, 2011 $_POST["modifyArray"] will only exist if at least one checkbox was checked... Link to comment https://forums.phpfreaks.com/topic/238151-problem-with-checkboxes-to-delete-multiple-entries/#findComment-1223801 Share on other sites More sharing options...
mpsn Posted June 2, 2011 Author Share Posted June 2, 2011 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> Link to comment https://forums.phpfreaks.com/topic/238151-problem-with-checkboxes-to-delete-multiple-entries/#findComment-1224216 Share on other sites More sharing options...
requinix Posted June 2, 2011 Share Posted June 2, 2011 What does print_r($_POST); output? Link to comment https://forums.phpfreaks.com/topic/238151-problem-with-checkboxes-to-delete-multiple-entries/#findComment-1224338 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.