Forums

PHP

This topic is locked

syntax error in INSERT statement

Posted 27 Dec 2001 20:04:42
1
has voted
27 Dec 2001 20:04:42 web warrior posted:
On every insert action I get this message :

[Microsoft][ODBC Microsoft Access-stuurprogramma] De instructie INSERT bevat een syntaxserror

Can't find any posts on this.

win2000 / pws / IIS / php4 / phakt1.1

Replies

Replied 28 Dec 2001 01:39:45
28 Dec 2001 01:39:45 Tim Green replied:
This is kind of difficult to diagnose without more information.

However, as ypu are using an Access Database, you should ensure that none of the table names contain any spaces or punctuation within them. Access will let you do this, however, PHP (and other server side languages) will not let you get away with this.

If this is not the case with your situation, please post the Insert Record PHP Code block here so we can see what is going on.

(Also, in the future do not post the same question multiple times in the forum. This can lead to the deletion of all the threads, and your problem would then go by unsolved. I appreciate this time it may have been done inadvertently, Many Thanks).

All the best


Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Edited by - rawveg on 28 Dec 2001 01:41:53
Replied 28 Dec 2001 11:27:07
28 Dec 2001 11:27:07 web warrior replied:
Thankz Tim,

And yes, I'll be more carefull posting the same question more than once. Actually I posted two questions in one the first time. Coz I thought they were related. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Anyway, there are NO spaces or special characters in the database. And note : it used to work fine (inserting records) before I upgraded my NT box to win2000 and the latest Phakt (1.1)..

And the database is not read only or anytrhing like that. As soon as I try to insert something a .ldb file is shown though. Also I've read articles on a ms access read / write bug, but no solutions other than switching to mysql was found.

Could it be that the access driver is corrupted? And if so, could one update/reinstall it?

Anywayz here is the insert code...

HaPHPy coding!!

Lars J.

Insert Code
---------------------------------
&lt;?php
// *** Edit Operations: declare Tables
$MM_editAction = $PHP_SELF;
if (isset(QUERY_STRING)){
$MM_editAction = $MM_editAction . "?" . $QUERY_STRING;
}

$MM_abortEdit = 0;
$MM_editQuery = "";
?&gt;&lt;?php
// *** Insert Record: set Variables

if (isset($MM_insert)){

// $MM_editConnection = MM_gpv1001_STRING;
$MM_editTable = "products";
$MM_editRedirectUrl = "";
$MM_fieldsStr = "prodcode|value|suppliercode|value|prodtitle|value|cat|value|subcat|value|summary|value|text|value|supplier|value|label|value|price|value|keywords|value|description|value|newimg|value|instockimg|value|display|value|stock|value|date|value|user|value|image1|value";
$MM_columnsStr = "prodcode|',none,''|suppliercode|',none,''|prodtitle|',none,''|cat|',none,''|subcat|',none,''|summary|',none,''|text|',none,''|supplier|',none,''|label|',none,''|price|',none,''|keywords|',none,''|description|',none,''|newimg|',none,''|instockimg|',none,''|display|',none,''|stock|',none,''|date|',none,''|user|',none,''|image1|',none,''";

// create the $MM_fields and $MM_columns arrays
$MM_fields = explode("|", $MM_fieldsStr);
$MM_columns = explode("|", $MM_columnsStr);

// set the form values
for ($i=0; $i+1 &lt; sizeof($MM_fields); ($i=$i+2)) {
$MM_fields[$i+1] = $$MM_fields[$i];
}

// append the query string to the redirect URL
if ($MM_editRedirectUrl && $QUERY_STRING && (strlen($QUERY_STRING) &gt; 0)) {
$MM_editRedirectUrl .= ((strpos($MM_editRedirectUrl, '?') == false)?"?":"&" . $QUERY_STRING;
}
}
?&gt;&lt;?php
// *** Insert Record: construct a sql insert statement and execute it
if (isset($MM_insert)) {
// create the sql insert statement
$MM_tableValues = "";
$MM_dbValues = "";
for ( $i=0; $i+1 &lt; sizeof($MM_fields); ($i=$i+2)) {
$formVal = $MM_fields[$i+1];
$MM_typesArray = explode(",", $MM_columns[$i+1]);
$delim = $MM_typesArray[0];
if($delim=="none" $delim="";
$altVal = $MM_typesArray[1];
if($altVal=="none" $altVal="";
$emptyVal = $MM_typesArray[2];
if($emptyVal=="none" $emptyVal="";
if ($formVal == "" || !isset($formVal)) {
$formVal = $emptyVal;
}
else {
if ($altVal != "" {
$formVal = $altVal;
}
else if ($delim == "'" { // escape quotes
$formVal = $delim . $formVal . $delim;
//$formVal = "'" . str_replace("'","\'",$formVal) . "'";
}
else {
$formVal = $delim . $formVal . $delim;
}
}
if ($i == 0) {
$MM_tableValues = $MM_tableValues . $MM_columns[$i];
$MM_dbValues = $MM_dbValues . $formVal;
}
else {
$MM_tableValues = $MM_tableValues . "," . $MM_columns[$i];
$MM_dbValues = $MM_dbValues . "," . $formVal;
}
}
$MM_editQuery = "insert into " . $MM_editTable . " (" . $MM_tableValues . " values (" . $MM_dbValues . "";
if ($MM_abortEdit!=1) {
// execute the insert
$queryrs = $gpv1001-&gt;Execute($MM_editQuery) or DIE($gpv1001-&gt;ErrorMsg());
if ($MM_editRedirectUrl) {
header ("Location: $MM_editRedirectUrl";
}
}
}
?&gt;
--------------
end code

Sometimes I do'nt get the INSERT error, but nothing is entered in the table.

Replied 29 Dec 2001 13:26:04
29 Dec 2001 13:26:04 Tim Green replied:
Looking briefly through your code I see that you are using 'text' and 'summary' as column names within your table.

I don't know if you are actually aware but these are reserved SQL function names, and it could well be these that are giving you the problem.

SQL (regardless of the database in use) can be a very strange beast. Some databases will tell you that you are using a keyword in your SQL like this, and others will just tell you that there is a parse error.

I suspect this is where your problem lies.

Anyway, I hope this helps.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 31 Dec 2001 21:06:34
31 Dec 2001 21:06:34 web warrior replied:
Thankz,

But I did tests with simple onetable, two field database and no luck either!! So again, I'm trying to figure this out..

Checked it all now, I'm pretty sure ;( ..

Lars J.

Replied 02 Jan 2002 01:10:52
02 Jan 2002 01:10:52 Tim Green replied:
OK, then the only other thing to ensure (as this is only happening on INSERTs) is that the uploaded ACCESS database has the correct permissions (0755 or 0777 to enable it for read/write).

I know the error message is specifying a syntax error, but when I took the code from your page and put it within UltraDev, it all seems to work just fine (I even created a table with the same fields) and didn't have to change the SQL at all.

Anyway, I hope this is of help.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 02 Jan 2002 12:43:38
02 Jan 2002 12:43:38 web warrior replied:
Thankz a lot Tim,

I had a feeling the code was correct since if followed and double checked every step. I'm not even gonna bother trying to repair this on win2000/iis. Since now I'm even losing DSN's on my system I'm pretty sure a fresh new config on my box will do the trick..

I'll put up the results here, so other users with this problem can at least find out some more about it.

Since I'm doing only a few simple inserts in my projects you saved my day. I'm pretty confident that they'll work ok on the live server wich is almost up..

Grtz,
Lars Johansson

------------------------------------
''Life is a bitch, but I will try''
------------------------------------


Reply to this topic