Page 1 of 1
Removing DB Entires
Posted: Sat Mar 05, 2005 8:54 pm
by volkan
Hi
I have a table, with a number on entries that must be manually deleted from the database.
What is the script for removing rows (entries) from a mysql table?
Posted: Sat Mar 05, 2005 9:02 pm
by John Cartwright
this is generally done like so..
1. you have have a unique ID on each row.. this can be accomplished by having a column (ID) set to autoincrement
2. You loop through your results, and create the links, adding the unique id on the link
Code: Select all
$result = mysql_query("SELECT * FROM `rows`") or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo '<a href="delete.php?id='.$rowї'id'].'">Delete ME</a>";
}
and then on delete.php you would have something like this
Code: Select all
if (!empty($_GETї'id']))
{
mysql_query("DELETE FROM `rows` WHERE `id` = '".$_GETї'id'].' LIMIT 1") or die(mysql_error());
}
for more information and syntax on mysql visit
http://dev.mysql.com/doc/mysql/en/index.html
Posted: Sun Mar 06, 2005 5:03 am
by volkan
Thanks for the reply.
Do i need to include a dbconnent.php?
Posted: Sun Mar 06, 2005 6:33 am
by JAM
volkan wrote:Thanks for the reply.
Do i need to include a dbconnent.php?
Likely, as you are connecting to the database prior to retrieving/deleting data.
Additionally, you do not crearly (for me

) mention if you are deleting
some or
all data in the table. If
all, you could look at the
TRUNCATE function.
Posted: Sun Mar 06, 2005 6:41 am
by volkan
Hi
I am trying to remove all the entires on the table!
That link doesn't contain the script for it.
What is the line?
Posted: Sun Mar 06, 2005 6:44 am
by JAM
volkan wrote:Hi
I am trying to remove all the entires on the table!
That link doesn't contain the script for it.
What is the line?

You should try to research your work before actually asking that, as it might be of critical interest of understanding these malicious functions...
Code: Select all
mysql_query('truncate table table_name');
Posted: Sun Mar 06, 2005 7:31 am
by volkan
Hi,
Sorry, i admit im impatient.
So....
Is this corrrect??:
REMOVE.php
Code: Select all
<?php
$result = mysql_query("SELECT * FROM `rows`") or die(mysql_error());
while ($row = mysql_fetch_assoc($result))
{
echo '<a href="delete.php">Delete ME</a>";
}
?>
and
delete.php
Code: Select all
<?php
include("DBCONNECT.php");
{
mysql_query('truncate table table_name') or die(mysql_error());
}
?>
{
mysql_query('truncate table table_name') or die(mysql_error());
}
?>
also,
what is a good book to learn about php + mysql insterface?
Posted: Sun Mar 06, 2005 7:46 am
by JAM
MySQL Manual wrote:13.1.9. TRUNCATE Syntax
TRUNCATE TABLE tbl_name
TRUNCATE TABLE empties a table completely. Logically, this is equivalent to a DELETE statement that deletes all rows, but there are practical differences under some circumstances.
Meaning, if you issue this command, you will empty the entire table. Links containing 'Delete ME' as in your REMOVE.php file are obsolete.
You can asweel link to/visit the delete.php directly (
http://www.example.com/delete.php ) and the data will be gone...
The delete.php only needs the truncate table query one time aswell.
Posted: Sun Mar 06, 2005 8:11 am
by volkan
i got ya,
so accessing delete.php
which contains:
Code: Select all
<?php
include("DBCONNECT.php");
{
mysql_query('truncate table table_name') or die(mysql_error());
}
?>
that only deletes the entires right? no the sql structure.
Posted: Sun Mar 06, 2005 8:16 am
by patrikG
MYSQL manual, PHP Manual and virtually any PHP book out there explain all this in great detail. Maybe it's time you did some work on this. Google can help you for sure. If in doubt, click the second link in my sig.
Topic locked.