By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,966 Members | 2,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,966 IT Pros & Developers. It's quick & easy.

Please help....

P: n/a
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\commit.php on line 91

Here is the code:

<?PHP

// PHP db connection
$db = 'C:\Phpweb\test.mdb';
$conn = new COM('ADODB.Connection') 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($_GET);

//$sql = "INSERT INTO Cards(";
$ids = "";
$values = "";

for ($i = 0; $i < sizeof($form_fields); $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,division,province,filetitle,air,water ,sewage,pttw,partVIII,part
46) VALUES ('1','ob','Ontario','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=create");
?>
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Matthew Paterson" <mp******@telus.net> wrote in message news:<3Jdxb.33828$oN2.6392@edtnps84>...
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\commit.php on line 91

Here is the code:

<?PHP

// PHP db connection
$db = 'C:\Phpweb\test.mdb';
$conn = new COM('ADODB.Connection') 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($_GET);

//$sql = "INSERT INTO Cards(";
$ids = "";
$values = "";

for ($i = 0; $i < sizeof($form_fields); $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,division,province,filetitle,air,water ,sewage,pttw,partVIII,part
46) VALUES ('1','ob','Ontario','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=create");
?>


I don't know your DB, I'm using MySQL ... have you tryed to print your
sql2 & sql99 so:

echo "[" . $sql99 . "]";
echo "<br>\n";
echo "[" . $sql2 . "]";

and then chech in html source "view source", if they are exactly the
same.
Jul 17 '05 #2

P: n/a
lazo wrote:
[...]
echo "[" . $sql99 . "]";
echo "<br>\n";
echo "[" . $sql2 . "]";

and then chech in html source "view source", if they are exactly the
same.


Why not have PHP itself check if the strings are equal? ???

if ($sql99 !== $sql2) echo '<B>STRINGS ARE DIFFERENT!</B>';
--
--= my mail address only accepts =--
--= Content-Type: text/plain =--
Jul 17 '05 #3

P: n/a
The problem is in here
// strip off last ,
$length = strlen($ids);
$ids[$length-1] = "";

$length = strlen($values);
$values[$length-1] = "";
The operation doesn't actually reduce these strings by one character,
it replaces the last character with char(0). Remember, unlike C, PHP
strings are not zero terminated. The terminal zero will hence get into
$sql99, which I guess JET interpret as the end of string character,
leaving your with

INSERT INTO
Cards(active,division,province,filetitle,air,water ,sewage,pttw,partVIII,part
46[TERMINATED]

Your webbrowser ignores the zeros, that's why the $sql99 and $sql2
look the same.

You should do the following instead:

$ids = substr($ids, 0, -1);
$values = substr($values, 0, -1);

"Matthew Paterson" <mp******@telus.net> wrote in message news:<3Jdxb.33828$oN2.6392@edtnps84>... 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\commit.php on line 91

Here is the code:

<?PHP

// PHP db connection
$db = 'C:\Phpweb\test.mdb';
$conn = new COM('ADODB.Connection') 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($_GET);

//$sql = "INSERT INTO Cards(";
$ids = "";
$values = "";

for ($i = 0; $i < sizeof($form_fields); $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,division,province,filetitle,air,water ,sewage,pttw,partVIII,part
46) VALUES ('1','ob','Ontario','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=create");
?>

Jul 17 '05 #4

P: n/a
YOU ARE A ROCKSTAR!!!

That was my problem - I would have never figured that out.....

You made my week!!!

Thanks again!!!!
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:a1**************************@posting.google.c om...
The problem is in here
// strip off last ,
$length = strlen($ids);
$ids[$length-1] = "";

$length = strlen($values);
$values[$length-1] = "";
The operation doesn't actually reduce these strings by one character,
it replaces the last character with char(0). Remember, unlike C, PHP
strings are not zero terminated. The terminal zero will hence get into
$sql99, which I guess JET interpret as the end of string character,
leaving your with

INSERT INTO

Cards(active,division,province,filetitle,air,water ,sewage,pttw,partVIII,part 46[TERMINATED]

Your webbrowser ignores the zeros, that's why the $sql99 and $sql2
look the same.

You should do the following instead:

$ids = substr($ids, 0, -1);
$values = substr($values, 0, -1);

"Matthew Paterson" <mp******@telus.net> wrote in message

news:<3Jdxb.33828$oN2.6392@edtnps84>...
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\commit.php on line 91

Here is the code:

<?PHP

// PHP db connection
$db = 'C:\Phpweb\test.mdb';
$conn = new COM('ADODB.Connection') 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($_GET);

//$sql = "INSERT INTO Cards(";
$ids = "";
$values = "";

for ($i = 0; $i < sizeof($form_fields); $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,division,province,filetitle,air,water ,sewage,pttw,partVIII,part 46) VALUES ('1','ob','Ontario','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=create");
?>

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.