Forum Moderators: coopster

Message Too Old, No Replies

DELETE FROM help

having problem with delete from query

         

paroa

5:28 am on Dec 6, 2008 (gmt 0)

10+ Year Member



Im having problem writing my cms. The part thats not working is the delete part...

<?php
session_start();
include 'config.php';
include 'opendb.php';
$_SESSION['modifyform'] = $_POST;
$modifycat = $_POST['modifycat'];
if(isset($_GET['del']))
{
$query = "DELETE FROM {$_SESSION['modifyform']['modifycat']} WHERE id = '{$_GET['del']}'";
mysql_query($query) or die('Error : ' . mysql_error());

exit;
}
?>

Ive searched everywhere but no solution

the error i come up with is

Error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = '3'' at line 1

If i put a table name where "{$_SESSION['modifyform']['modifycat']}" is it works fine.

Can anyone point me in the right direction?

Anyango

6:20 am on Dec 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld Paroa!

A couple of things

1) If you are getting values from $_POST and then in your if{} condition you are checking for a $_GET ? i am not sure if both of them will work together ?

2) why not simply

<?php
$modifycat = $_POST['modifycat'];
$id=$_POST['del'];

if(isset($_POST['del']))
{
$query = "DELETE FROM $modifycat WHERE id = $id";
mysql_query($query) or die('Error : ' . mysql_error());

exit;
}
?>

That makes it easier to work with, if it still does not work then try to echo your $query before execution to see if the generated query is fine

[edited by: Anyango at 6:21 am (utc) on Dec. 6, 2008]

paroa

8:18 am on Dec 6, 2008 (gmt 0)

10+ Year Member



Thank you Anyango for your quick reply, i echoed "{$_SESSION['modifyform']['modifycat']}" and it came up with the correct value, the value is the table name, if i put in the actual name of the table it works, it also works with the select from query, just not the delete? this is the link which calls the query

<a href="javascript:delArticle('<?php echo $id;?>', '<?php echo $item_name;?>');">delete</a>