zero-perfoliate
zero-perfoliate

Author Topic: DELETE FROM help...  (Read 696 times)

Offline paroa

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
DELETE FROM help...
« on: December 06, 2008, 03:34:20 PM »
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']}" , it works fine.

I use the same variable in a "SELECT FROM" query, and it works fine, if i echo "{$_SESSION['modifyform']['modifycat']}" it comes up with the correct value

this is the link which calls the query
<a href="javascript:delArticle('<?php echo $id;?>', '<?php echo $item_name;?>');">delete[/url]

and heres the javascript

<script language="JavaScript">
function delArticle(id, item_name)
{
if (confirm("Are you sure you want to delete '" + item_name + "'"))
{
window.location.href = 'modify.php?del=' + id;
}
}
</script>


Can anyone point me in the right direction?

Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: DELETE FROM help...
« Reply #1 on: December 16, 2008, 06:29:07 PM »
what do u get if you print out $_SESSION['modifyform']['modifycat']?

 

zero-perfoliate