Can anyone tell me why in the code below the sql execute that uses $sql99
does not work while the one with $sql2 works. $sql99 is exactly the same as
$sql2 when printed out.
I get an error saying:
Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft
JET Database Engine Description: Syntax error in INSERT INTO statement. in
c:\phpweb\commi t.php on line 91
Here is the code:
<?PHP
// PHP db connection
$db = 'C:\Phpweb\test .mdb';
$conn = new COM('ADODB.Conn ection') or die("Cannot start ADO");;
$conn->Open("Provider =Microsoft.Jet. OLEDB.4.0; Data Source=$db");
import_request_ variables(gp, "");
$filetitle = "";
$form_fields = array_keys($_GE T);
//$sql = "INSERT INTO Cards(";
$ids = "";
$values = "";
for ($i = 0; $i < sizeof($form_fi elds); $i++) {
$build_sql = 1;
$thisField = $form_fields[$i];
$thisValue = $HTTP_GET_VARS[$thisField];
// check defualt values and change them to blank
if($thisValue == "insert approval #" || $thisValue == "insert file #")
$thisValue = "";
// concatinate file number
if($thisField == "filetitle_ 1"){
$filetitle = $filetitle . $thisValue . " ";
$build_sql = 0;
}
if($thisField == "filetitle_ 2"){
$filetitle = $filetitle . $thisValue . " ";
$build_sql = 0;
}
if($thisField == "filetitle_ 3"){
$filetitle = $filetitle . $thisValue . " ";
$build_sql = 0;
}
if($thisField == "filetitle_ 4"){
$filetitle = $filetitle . $thisValue;
//echo "filetitle" . " = " . $filetitle . "<br>";
$build_sql = 0;
$ids = $ids . "filetitle, ";
$values = $values . "'" . $filetitle . "'" . ",";
}
if($build_sql == 1 && $thisValue != "") {
if($thisField != "submit") {
$ids = $ids . "" . $thisField . ",";
$values = $values . "'" .$thisValue . "'" . ",";
}
}
}
// strip off last ,
$length = strlen($ids);
$ids[$length-1] = "";
$length = strlen($values) ;
$values[$length-1] = "";
$sql99="";
$sql99 = "INSERT INTO Cards(" . $ids . ") VALUES (" . $values . ")";
$sql99 = trim($sql99);
// PHP db connection
$sql2 = "INSERT INTO
Cards(active,di vision,province ,filetitle,air, water,sewage,pt tw,partVIII,par t
46) VALUES ('1','ob','Onta rio','0 0 0 0','0','0','0', '0','0','0') ";
$query = $conn->Execute($sql99 );
$query = $conn->Execute($sql2) ;
echo $sql99;
echo "<br>";
echo $sql2;
$conn->Close;
//header ("Location: ./admin.card.view .php?action=cre ate");
?>
does not work while the one with $sql2 works. $sql99 is exactly the same as
$sql2 when printed out.
I get an error saying:
Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft
JET Database Engine Description: Syntax error in INSERT INTO statement. in
c:\phpweb\commi t.php on line 91
Here is the code:
<?PHP
// PHP db connection
$db = 'C:\Phpweb\test .mdb';
$conn = new COM('ADODB.Conn ection') or die("Cannot start ADO");;
$conn->Open("Provider =Microsoft.Jet. OLEDB.4.0; Data Source=$db");
import_request_ variables(gp, "");
$filetitle = "";
$form_fields = array_keys($_GE T);
//$sql = "INSERT INTO Cards(";
$ids = "";
$values = "";
for ($i = 0; $i < sizeof($form_fi elds); $i++) {
$build_sql = 1;
$thisField = $form_fields[$i];
$thisValue = $HTTP_GET_VARS[$thisField];
// check defualt values and change them to blank
if($thisValue == "insert approval #" || $thisValue == "insert file #")
$thisValue = "";
// concatinate file number
if($thisField == "filetitle_ 1"){
$filetitle = $filetitle . $thisValue . " ";
$build_sql = 0;
}
if($thisField == "filetitle_ 2"){
$filetitle = $filetitle . $thisValue . " ";
$build_sql = 0;
}
if($thisField == "filetitle_ 3"){
$filetitle = $filetitle . $thisValue . " ";
$build_sql = 0;
}
if($thisField == "filetitle_ 4"){
$filetitle = $filetitle . $thisValue;
//echo "filetitle" . " = " . $filetitle . "<br>";
$build_sql = 0;
$ids = $ids . "filetitle, ";
$values = $values . "'" . $filetitle . "'" . ",";
}
if($build_sql == 1 && $thisValue != "") {
if($thisField != "submit") {
$ids = $ids . "" . $thisField . ",";
$values = $values . "'" .$thisValue . "'" . ",";
}
}
}
// strip off last ,
$length = strlen($ids);
$ids[$length-1] = "";
$length = strlen($values) ;
$values[$length-1] = "";
$sql99="";
$sql99 = "INSERT INTO Cards(" . $ids . ") VALUES (" . $values . ")";
$sql99 = trim($sql99);
// PHP db connection
$sql2 = "INSERT INTO
Cards(active,di vision,province ,filetitle,air, water,sewage,pt tw,partVIII,par t
46) VALUES ('1','ob','Onta rio','0 0 0 0','0','0','0', '0','0','0') ";
$query = $conn->Execute($sql99 );
$query = $conn->Execute($sql2) ;
echo $sql99;
echo "<br>";
echo $sql2;
$conn->Close;
//header ("Location: ./admin.card.view .php?action=cre ate");
?>
Comment