dessolator Posted January 22, 2008 Share Posted January 22, 2008 Hi, I have a table of all the users registered for my website in my admin area, I have a column of checkboxes in the delete column where the values are equal to the member id so that when selected I can delete multiple users but I have created a quick process page to see what is being returned and it is only one of the selected boxes values when I would like several. I don't know if I need some kind of array to store it in (but I haven't really used arrays much yet). I was wondering if you could help please. Thanks, Ian Table <html> <style type="text/css"> <!-- .style1 {color: #FFFFFF} .style2 {color: #CCCCCC} --> </style> <form id="deleteform" name="deleteform" method="post" action="deletetest.php"> </html> <? $host="localhost"; // Host name $username="root"; // Mysql username $password="abc123"; // Mysql password $db_name="colab_booking"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //Database - Assigns the below statement into the variable query $query = "SELECT member_id, forename, surname, email, username FROM members"; $result = mysql_query($query); //$row = mysql_fetch_row($result); echo "<center><h3>View all users</h3></center>"; echo '<table border=0 align="center"> <tr> <th align="center" background="http://localhost/colab/test/admin/images/thead_bg.gif"><div class="style1">UID</div></th> <th align="center" background="http://localhost/colab/test/admin/images/thead_bg.gif"><div class="style1">Forename</div></th> <th align="center" background="http://localhost/colab/test/admin/images/thead_bg.gif"><div class="style1">Surname</div></th> <th align="center" background="http://localhost/colab/test/admin/images/thead_bg.gif"><div class="style1">Email</div></th> <th align="center" background="http://localhost/colab/test/admin/images/thead_bg.gif"><div class="style1">Username</div></th> <th align="center" background="http://localhost/colab/test/admin/images/thead_bg.gif"><div class="style1">Delete User</div></th> </tr>'; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td bgcolor='#EFEFEF' align='center'>".$row[0] . " "."</td>"; echo "<td bgcolor='#EFEFEF' align='center'>".$row[1] . " "."</td>"; echo "<td bgcolor='#EFEFEF' align='center'>".$row[2] . " "."</td>"; echo "<td bgcolor='#EFEFEF' align='center'>".$row[3] . " "."</td>"; echo "<td bgcolor='#EFEFEF' align='center'>".$row[4] . " "."</td>"; echo "<td bgcolor='#EFEFEF' align='center'><input type='checkbox' name='delete' value='$row[0]'/></td>"; } echo "</tr>"; echo "</table>"; ?> <center><input type='submit' name='submit' value='Submit'/></center> </form> Process form: <?php $delete_id = substr($_POST['delete'], 0, 65); echo $delete_id; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87263-solved-using-checkboxes-to-delete-many-users-atm-only-deleting-1/ Share on other sites More sharing options...
rhodesa Posted January 22, 2008 Share Posted January 22, 2008 change echo "<td bgcolor='#EFEFEF' align='center'><input type='checkbox' name='delete' value='$row[0]'/></td>"; to echo "<td bgcolor='#EFEFEF' align='center'><input type='checkbox' name='delete[]' value='$row[0]'/></td>"; then, in your PHP file, $_POST['delete'] will be an array and you can just loop through it: <?php if($_POST['delete']){ foreach($_POST['delete']){ //put code here } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87263-solved-using-checkboxes-to-delete-many-users-atm-only-deleting-1/#findComment-446355 Share on other sites More sharing options...
dessolator Posted January 22, 2008 Author Share Posted January 22, 2008 Hi, thanks for your reply. I just tested the Post code out and am getting this error message: Parse error: parse error, unexpected ')' in D:\xampp\htdocs\colab\test\admin\deletetest.php on line 3 I have already fiddled about with it taking the ) out etc and still get the errors. I'm really confused bcaus the code looks fine. Thanks, Ian Quote Link to comment https://forums.phpfreaks.com/topic/87263-solved-using-checkboxes-to-delete-many-users-atm-only-deleting-1/#findComment-446361 Share on other sites More sharing options...
rhodesa Posted January 22, 2008 Share Posted January 22, 2008 oops...looks like it's time for another coffee <?php if($_POST['delete']){ foreach($_POST['delete'] as $id){ echo "Delete this id: {$id}\n"; //put code here } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87263-solved-using-checkboxes-to-delete-many-users-atm-only-deleting-1/#findComment-446372 Share on other sites More sharing options...
dessolator Posted January 22, 2008 Author Share Posted January 22, 2008 Lol, thanks very much for your help much appreciated, I'm learning slowly. Ian Quote Link to comment https://forums.phpfreaks.com/topic/87263-solved-using-checkboxes-to-delete-many-users-atm-only-deleting-1/#findComment-446379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.