Help - Search - Members - Calendar
Full Version: Mysql Delete Question
Zymic Webmaster Forums > Zymic Free Web Hosting > Databases & MySQL
iStriide
Does anybody know how I would be able to delete values or rows from a MySQL table with PHP commands or functions.

Example:

Say I have a Admin Control Panel and I want to click a button that says "Delete User". What kind of code PHP code would I have to use to make this happen.
Leonid@samisu
You first need to connect to the database using a code like
CODE
mysql_connect(localhost, $dbUser, $dbPass);
@mysql_select_db($db) or die('Unable to select database');

Then you need to issue an SQL querry like this
CODE
$deleteResult = mysql_query("DELETE * FROM User WHERE Id = $id");
if (! $deleteResult)
    echo 'Invalid query: ' . mysql_error() . '<br />';

Then close the connection to the database
CODE
mysql_close();
adam007
<?php
// Connect to MySQL

// Delete Bobby from the "example" MySQL table
mysql_query("DELETE FROM example WHERE age='15'")
or die(mysql_error());
?>
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-2013 Invision Power Services, Inc.