Page 1 of 1

DELETE FROM WHERE help....

Posted: Sat Dec 06, 2008 5:53 pm
by paroa
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</a>

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?

Re: DELETE FROM WHERE help....

Posted: Sat Dec 06, 2008 9:12 pm
by Kieran Huggins
Have you started the session yet in this script?

session_start()

Re: DELETE FROM WHERE help....

Posted: Sun Dec 07, 2008 6:28 pm
by paroa
Yeah, ive started the session, its my very first line of code....

if i echo "$_SESSION['modifyform'] = $_POST;" outside of this code

"""""""""""""""""""""""""""""""""""""
if(isset($_GET['del']))
{
$query = "DELETE FROM {$_SESSION['modifyform']['modifycat']} WHERE id = '{$_GET['del']}'";
mysql_query($query) or die('Query sent: ' . $query . '<br><br>Error : ' . mysql_error());

exit;
}
""""""""""""""""""""""""""""""""""""
it prints the value...but as soon as it goes between that code...it doesnt print anything? the only thing i can think of is the get and post are conflicting, but i thought even if i store the post value in another variable...and place it in..it will work..but that doesnt work either? any ideas?