[SOLVED] Deleting mysql data with link?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

[SOLVED] Deleting mysql data with link?

Post by dominod »

Hi

I have a list of mysql data entries on a webpage like:

1 name1 email1
2 name2 email2
3 name3 email3
ect.

How can I delete an entire row (id, name and email) from that database using a link so it will look like:

1 name1 email 1 - delete this (clicking on this link will delete this row)

I Googled around and found this:

http://www.totallyphp.co.uk/code/delete ... tabase.htm

Code: Select all

<?php 

/* 
 * Change the first line to whatever 
 * you use to connect to the database. 
 * 
 * Change tablename to the name of your  
 * database table. 
 * 
 * This example would delete a row from 
 * a table based on the id of the row. 
 * You can change this to whatever you 
 * want. 
 */ 

// Your database connection code 
db_connect(); 

$query = "DELETE FROM tablename WHERE id = ('$id')"; 

$result = mysql_query($query); 

echo "The data has been deleted."; 

?> 
What I dont understand is how to trigger this when clicking on a link .. :?:

Anyone got some suggestions?

Thanks in advance!
dominod
Forum Commoner
Posts: 75
Joined: Wed Jun 30, 2010 7:18 am

Re: Deleting mysql data with link?

Post by dominod »

Problem solved :)
Post Reply