Help - Search - Members - Calendar
Full Version: Link To Delete Data From Mysql
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
loveandasandwich
Hello,

I was hoping someone could tell me how to create a link to delete a specific row from a MySQL database. I have a list of products, and when once sells, I want to be able to click "Delete" so the product is deleted from the database.
I used to know how. But I forgottt. :[[[

pid is the primary key with INT data type.
I want the delete link to be after the link in the echo.
CODE
<?php
require_once('ideas.php');

    if (!dbConnect()) {
        echo 'Error connecting to database';
        exit;
    }

$query = "SELECT `pid`, `name`, `desc`, `url`, `image`, `price`, date_format(`date`,'%M %d, %Y') FROM products ORDER BY date DESC";
$result = mysql_query($query) or die(mysql_error());

while(list($pid,$name,$desc,$url,$image,$price,$date)= mysql_fetch_row($result))
{
    echo "$pid, <a href='$url'>$name</a>";
}

?>


Thanks a ton!
mahadiwinata
CODE
$sql = "DELETE FROM tableName WHERE id=' ".$id." ' ";


Good luck smile.gif rolleyes.gif
Adam
You will want to link to another page which connects to your database and run a SQL query like:

CODE
mysql_query('DELETE from `TABLE` WHERE `id` = "'.$id.'" LIMIT 1 ');


If you make sure that LIMIT 1 is kept, it protects the SQL query from deleting mutipal entries, you may also want to protect the page so only you can access it.
sclek
QUOTE(Adam @ Jul 20 2008, 01:27 AM) *
You will want to link to another page which connects to your database and run a SQL query like:

CODE
mysql_query('DELETE from `TABLE` WHERE `id` = "'.$id.'" LIMIT 1 ');


If you make sure that LIMIT 1 is kept, it protects the SQL query from deleting mutipal entries, you may also want to protect the page so only you can access it.

I was always wondering what LIMIT 1 does. Thanks.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.