Jump to content

Delete Database result with Checkbox


Unholy Prayer

Recommended Posts

Ok, I'm writing a support script for my website which includes an admin area where admins can delete the support complaints but right now it's only with links.  How would I make it so it displays a check box that would delete only the checked complaint?  This is my code:

 

<?php
require_once('config.php');

include('includes/header.tpl');

$act = $_GET['act'];

if($act=='')
{
   echo "<td align='center' class='content'><table align='center' width='50%' cellspacing='0' cellpadding='2' border='0'>
          <tr>";

$result = mysql_query("select * from support");

while($r=mysql_fetch_array($result))
   {	
   
   $id=$r["id"];
   $username=$r["username"];
   $email=$r["email"];
   $content=$r["content"];   
  
   echo "<td align='left' colspan='2'>$username says:</a></td>
           </tr><tr>
         <td align='left' colspan='2'>$content<br><br></td>
           </tr><tr>
         <td align='left'><a href='support.php?act=delete&id=$id'>Delete</a></td>
         <td align='right'><a href='mailto:$email'>Reply to Complaint</a><br><br></td>
</tr><tr>";
   }

echo "</table></td>";
}




$sid = $_GET['id'];



if($act=="delete")
{
    $sql = "DELETE FROM support WHERE id=$sid";
    $result = mysql_query($sql);
    echo "<td align='center'>The complaint has been deleted.<br>Click <a href='support.php'>here</a> to return to the support management page.</td>";
}

?>

Link to comment
Share on other sites

You would have to use a form. Have the form feed the script the id of the record to be deleted (much like you are doing now). If you would want more than one then you can catch them in an array and use a while loop to then delete all of them that were passed to the script.

 

Sorry but I don't have time to write type the whole code out.

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.