SQL Delete syntax - Syntax error in query. Incomplete query?
Posted: Sat Mar 29, 2003 11:55 pm
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
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