Select one or multiple records and then delete them
Posted: Thu Jan 17, 2008 10:29 am
Hi,
I have a little database, I can search for records and display them in an html table,
I would like to have a check box of every record returned by the search and a button that onclick will delete the selected records from the database.
I am far away from having any idea on where to start on this.
Below is my result script:
I have a little database, I can search for records and display them in an html table,
I would like to have a check box of every record returned by the search and a button that onclick will delete the selected records from the database.
I am far away from having any idea on where to start on this.
Below is my result script:
Code: Select all
$host = "localhost";
$user = "****";
$pass = "*****";
$dbname = "contacts";
$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);
$search = mysql_real_escape_string($_POST['search']);
$result = mysql_query("SELECT * FROM contacts where first_name LIKE '%{$search}%' OR last_name LIKE '%{$search}%' OR company_name LIKE '%{$search}%' OR website LIKE '%{$search}%' OR street LIKE '%{$search}%' OR city LIKE '%{$search}%' OR zip LIKE '%{$search}%' OR country LIKE '%{$search}%' OR mail1 LIKE '%{$search}%' OR mail2 LIKE '%{$search}%' OR phone LIKE '%{$search}%' OR mobile LIKE '%{$search}%' OR card LIKE '%{$search}%' OR birthday LIKE '%{$search}%'") or die (mysql_errno().": ".mysql_error()."<BR>");
echo "<table border=0 width=1400>
<tr bgcolor=#87ceeb font face=tahoma>
<td width=100><b><font face=tahoma>First Name</td><td width=100><b><font face=tahoma>Last Name</td>
<td width=100><b><font face=tahoma>Company Name</td><td width=100><b><font face=tahoma>Website</td>
<td width=100><b><font face=tahoma>Street + Number</td><td width=100><b><font face=tahoma>City</td>
<td width=100><b><font face=tahoma>Post Code</td><td width=100><b><font face=tahoma>Country</td>
<td width=100><b><font face=tahoma>E-Mail 1</td><td width=100><b><font face=tahoma>E-Mail 2</td>
<td width=100><b><font face=tahoma>Phone</td><td width=100><b><font face=tahoma>Mobile</td>
<td width=100><b><font face=tahoma>Christmas Card</td><td width=100><b><font face=tahoma>Birthday</b></td>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr bgcolor=#4682b4>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['first_name'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['last_name'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['company_name'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['website'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['street'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['city'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['zip'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['country'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['mail1'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['mail2'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['phone'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['mobile'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['card'] . "</td>";
echo "<td><font color=#FFFFFF font face=Tahoma>" . $row['birthday'] . "</font></td>";
echo "</tr>";
}
echo "</table>";
?>