Jump to content

[SOLVED] Using checkboxes to delete many users (atm only deleting 1)


dessolator

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.