Jump to content


Wierd INSERT INTO problem with ODBC

  • Please log in to reply
1 reply to this topic

#1 Thrakorzog

  • New Members
  • Pip
  • Newbie
  • 2 posts
  • LocationSouthern Indiana

Posted 13 September 2006 - 06:05 PM

I am not exactly a new-b, but I am not so old hat to know what's going on with this one, and can use some sage advice.

I have the following code that fails:
//Create Tasks
for ($n = 0 ; $n < count ($TN) ; $n++)
$sql="INSERT INTO Task (ParentProject, ParentTask, Desc, TimeEstimate, Lvl) ";
$sql=$sql."VALUES (";
$sql=$sql."0, ";
$sql=$sql.$proj_ID.", ";
$sql=$sql."'".$TN[$n]."', ";
$sql=$sql.$TT[$n].", ";

$rs=odbc_exec($conn,$sql); //<-this is line 77
if (!$rs)


  exit("Error in SQL:".$sql);



OK, it looks clean, but that usually means you have a database side problem except for two factors:
1) I have another statement just a few lines up that calls successfully:
//Create SQL statement
$sql="INSERT INTO Project (ProjName, POC, ScopeState, DesignConcepts, Deliverables, ";
$sql=$sql."Boundaries, SuccessCriteria, Resources, RisksMit, Assumptions, ";
$sql=$sql."StakeHolders, ProjectManager, ProjectSponsor) ";
$sql=$sql."VALUES ('".$PN."', '".$PC."', '".$SC."', '".$DC."', '".$DE;
$sql=$sql."', '".$BO."', '".$SU."', '".$RS."', '".$RM."', '".$AS;
$sql=$sql."', '".$ST."', ".$PM.", ".$PS.")";

//Execute SQL statement

if (!$rs)


  exit("Error in SQL:".$sql);


//Get ID just inserted Into Database

//Execute SQL statement

if (!$pre_rs)


exit("Error in SQL".$pre_sql);


while (odbc_fetch_row($pre_rs))





and .......
2) the error indicates a problem with my syntax:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in C:\Webroot\matrix\Olive\Functions\NewProjectCreate.php on line 77
Error in SQL:INSERT INTO Task (ParentProject, ParentTask, Desc, TimeEstimate, Lvl) VALUES (0, 0, '1', 1, 0)

Thanks for any insight.
T |-| R /- |<

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 17 September 2006 - 10:40 AM

DESC is SQL reseved word. I recommend you change the column name, say 'description'
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users