Hi, I have a script that prints out a news article from a database, along with all the comments associated with it. I'm linking this page using: <a href=\"comments.php?ID=$ID\">. This works fine.
At the bottom of the page, there is a form to add a new comment. Whenever I fill in the form and submit it, I get:
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'ID ='., SQL state 37000 in SQLExecDirect in c:\program files\apache group\apache\htdocs\nc\comments.php on line 12
Warning: Supplied argument is not a valid ODBC result resource in c:\program files\apache group\apache\htdocs\nc\comments.php on line 15
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'PostID ='., SQL state 37000 in SQLExecDirect in c:\program files\apache group\apache\htdocs\nc\comments.php on line 41
Warning: Supplied argument is not a valid ODBC result resource in c:\program files\apache group\apache\htdocs\nc\comments.php on line 43
My code (excluding the html):
$dbConnect = odbc_pconnect("News", "NC", "TEST");
//Print news article
$Query1 = "SELECT * FROM News WHERE ID = $ID";
$Result1 = odbc_exec($dbConnect, $Query1);
print("<table bgcolor=\"#A8B2BE\" width=\"100%\">\n");
while(odbc_fetch_row($Result1))
{
$Author = stripslashes(odbc_result($Result1, 1));
$PostDate = odbc_result($Result1, 2);
$Title = stripslashes(odbc_result($Result1, 3));
$Post = stripslashes(odbc_result($Result1, 4));
$IP = odbc_result($Result1, 6);
$msgID = odbc_result($Result1, 5);
}
$Query2 = "SELECT * FROM Comments WHERE PostID = $msgID";
$Result2 = odbc_exec($dbConnect, $Query2);
while(odbc_fetch_row($Result2))
{
$CAuthor = odbc_result($Result2, 3);
$CDate = odbc_result($Result2, 4);
$CHeader = odbc_result($Result2, 5);
$Comment = odbc_result($Result2, 6);
if($Result2 != " ")
{
print("<table bgcolor=\"#A8B2BE\" width=\"100%\">\n");
print("<tr>\n");
print("<td><b><font size=\"2\" face=\"Verdana\">$CHeader</font></b> - <font size=\"1\" face=\"Verdana\">[by $CAuthor - $CDate]</font></td>\n");
print("</tr>\n");
print("</table>\n");
print("<font size=\"2\" face=\"Verdana\">$Comment</font>\n");
print("<br>\n");
print("<br>\n");
}
}
if($Submit)
{
$CQuery = "INSERT INTO Comments (Author, CommentDate, Header, Comment) VALUES ('$Name', now(), '$Header', '$Msg')";
odbc_do($dbConnect, $CQuery);
}
Sorry if this is really long 🙂. I know there's probably a simple solution, but can't think what.
Any help appreciated, thanx.