I have a database where i am trying to delete ALL entries for the particular user. Problem is, its only allowing me to delete one by one.
Have included the code to the db's in question, and the associated php code.
If you can look over this, and let me know where I am going wrong, it would be very appreciated.
I would like to list by username and to be able to delete all records for that user name (in the db) with one click if possible.
Thanks.
TABLE STRUCTURE
CREATE TABLE contactbook (
id int(11) NOT NULL auto_increment,
username text NOT NULL,
contactuser text NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM PACK_KEYS=0 AUTO_INCREMENT=1;
DELETE SCRIPT FOR USER LISTING (BELOW)
<?php
include("../config.php");
?>
<?php
$connection = mysql_connect("$server", "$db_user", "$db_pass");
$db = mysql_select_db("$database", $connection);
$query = "DELETE * FROM contactbook WHERE username = '$username'";
$result = mysql_query($query, $connection);
?>
<?php echo "User contact book has been deleted"; ?>
USER LISTING (ANY WAY I CAN ONLY LIST THE USERNAME ONCE EVEN THOUGH THERE WOULD BE MANY ENTRIES FOR THAT USER? BUT DELETING ALL ENTRIES FOR THAT USER WHEN "DELETE" LINK HAS BEEN CLICKED ON?)
<?php
include("../config.php");
?>
<?php
$connection = mysql_connect("$server", "$db_user", "$db_pass");
$db = mysql_select_db("$database", $connection);
$query = "SELECT FROM contactbook order by username asc";
$result = mysql_query($query, $connection);
echo "<table border=\"1\">";
echo "<tr><td><b>Username</b></td><td><b>Delete?</b></td></tr>";
while ($rows = mysql_fetch_array($result))
{
echo "<tr><td>$rows[username]</td><td><a href=\"delcontactbook.php?user=$rows[username]\">Delete</a></td></tr>";
}
echo "</table>";
?>
Thanks in advance.