Log in

View Full Version : Resolved Deleting SQL Entries with a PHP form



Lumpy500
03-14-2009, 07:25 PM
Im in need of a lil help here.

atm ive been learning up with php and sql, tho im stuck with the connection between allowing to delete.

i went on a google hunt and found this:


<?PHP
$dbuser="gamer_simple";
$dbpass="*******";
$dbname="gamer_simplephp"; //the name of the database
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);

$mainsection="forum_question"; //The name of the table where web links are stored
$idno=1;
$query1="delete from " . $mainsection . " where id = " . $idno;
mysql_db_query($dbname, $query1) or die("Failed Query of " . $query1);
echo "Forum Question with ID " . $idno . " has been deleted as requested.<br>";
?>

Im looking for something like that, tho with a form which shows all the ID,s and titles with a tick box next to them. so its easier to delete them without having to keep changing it an uploading via ftp then going to the script.

ive posted here before and u didnt let me down. i hope this trip is the same :D

Nile
03-15-2009, 01:00 AM
Maybe this (http://www.phpeasystep.com/mysqlview.php?id=8)?

JasonDFR
03-15-2009, 07:45 AM
Here is the correct syntax for deleting:


$q = "DELETE FROM `table` WHERE `table`.`column` = 'value' LIMIT 1;

Place double quotes around the whole query string. Place single quotes around variables. Place `forward ticks` around database and column names. DO NOT quote integers.

For your example, $mainsection is a column name, so place `forwardticks` around it. id is a column name so it gets forward ticks. $idno is a variable and would normally get 'single quotes', but since it is an integer, do not quote it. LIMIT 1 makes sure only one row is deleted.


$q = "DELETE FROM `$mainsection` WHERE `id` = $idno LIMIT 1 ";

Good Luck,

J

Lumpy500
03-15-2009, 04:43 PM
jason, thanks for the help but i was looking for more of a form which did it.

Nile got it just perfect :D

thanks a bunch mate.

Nile
03-17-2009, 01:30 AM
Great! Glad to help you! Your welcome!

It seems your topic is solved... Please set the status to resolved.. To do this:
Go to your first post ->
Edit your first post ->
Click "Go Advanced" ->
Then in the drop down next to the title, select "RESOLVED"