SQL Delete syntax - Syntax error in query. Incomplete query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
vaughty
Forum Newbie
Posts: 2
Joined: Tue Mar 25, 2003 5:02 pm
Location: Lancaster

SQL Delete syntax - Syntax error in query. Incomplete query?

Post by vaughty »

I'm trying to write a simple forum for part of my university coursework using PHP and Access, so far I have been able to post a new topic and display all the topics.

I am trying to implement a delete function which I think should work but I get the error

Syntax error in query. Incomplete query?

Here's my code, I've tried loads of different ways to change it but with no joy.

This is the code for delete.php which lets you choose the post to delete and then forwards you to delete_post.php
<?php
// This is the DSN we have create for our database
$connect = odbc_connect("forum", "root", "");
?>

<html>
<body>
<?php

shownode(0); // display all the main threads

// This function is a recursive function which shall display all the br /anches
// and sub br /anches of the threads
function shownode($nodecode)
{
global $connect; // using the global variable for connection
// Get a list of all the sub nodes which specific parentcode
$noderesult = odbc_exec($connect,"select * from forum where parentcode = $nodecode");
echo '<ul type="disc">';
while(odbc_fetch_row($noderesult)) // get all the rows
{
$code = odbc_result($noderesult,"code");
$title = odbc_result($noderesult,"title");
$uname = odbc_result($noderesult,"uname");
$email = odbc_result($noderesult,"email");
echo "<li>";
echo "<a href=\"delete_post.php?node=$code\"> $title </a>";
echo "-- by ($uname) $email<br />";
shownode($code);
}
echo "</ul>";
}
?>
</body>
</html>

This is the code for delete_post.php which doesn't work.
<?php
$title=$_POST['title'];
$description=$_POST['description'];
$postname=$_POST['postname'];
$email=$_POST['email'];
$connect = odbc_connect("forum", "root", "");

// insert the record in the database
$resultupdate=odbc_exec($connect,"delete from 'forum' where 'parentcode' = '$nodecode' limit 1");
header(Location:"delete.php");
exit;
?>
Any help would be really appreciated
Thanks,
Tom
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post by haagen »

I think this can be your problem. Change

Code: Select all

$resultupdate=odbc_exec($connect,"delete from 'forum' where 'parentcode' = '$nodecode' limit 1");
to

Code: Select all

$resultupdate=odbc_exec($connect,"delete from forum where parentcode = '$nodecode' limit 1");
Post Reply