Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(ODBC) Syntax error in INSERT INTO statement. 1

Status
Not open for further replies.

mptrew

MIS
Sep 7, 2001
42
GB
Can somebody please tell me what is wrong with the code below. If the record exists then part one works but if not I get the above syntaxt error message


$db=odbc_connect($dsn,$usr,$pass);
//echo &quot;Current Directory - $cur_dir<br>&quot;;
if (!$db) {
Echo &quot;Unable to open db - $dsn<br>&quot;;
} else {
$query=&quot;SELECT * &quot;;
$query.=&quot;FROM pages &quot;;
$query.=&quot;WHERE page= '$page' &quot;;
$result=odbc_do($db,$query);
$num=odbc_num_rows($result);
$ID=intval(odbc_result($result,1));
echo &quot;Database returned $num rows. This record is '$ID'<br>&quot;;
if ($ID>=1) {
$hits=intval(odbc_result($result,3));
echo &quot;$ID.$page was $hits hits, &quot;;
$num=$hits+1;
echo &quot;now $num hits.<br>&quot;;
$query=&quot;UPDATE pages &quot;;
$query.=&quot;SET hits=$num &quot;;
$query.=&quot;WHERE ID=$ID &quot;;
$result=odbc_do($db,$query);
} else {
$num=1;
echo &quot;New row - $page - $num<br>&quot;;
$query=&quot;INSERT INTO pages &quot;;
$query.=&quot;SET page='$page', hits='$num'; &quot;;
$result=odbc_do($db,$query);
}
}
 
Wrong INSERT syntax.
Use this :

INSERT INTO pages (field1,field2)
VALUES ('$value1','$value2')

cheers.. devnull22

--
Apparently if you play the Windows NT CD backwards you hear satanic messages. If you think that's bad, play it forwards and it installs Windows NT !
 
I'm trying to connect to an Access database with ODBC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top