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");
?> 4 2071
"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.
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 =--
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"); ?>
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"); ?> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Kurt Watson |
last post by:
I’m having a different kind of problem with Hotmail when I sign in it
says, "Web Browser Software Limitations
Your Current Software Will Limit Your Ability to Use Hotmail
You are using a web...
|
by: x muzuo |
last post by:
Hi guys,
I have got a prob of javascript form validation which just doesnt work
with my ASP code. Can any one help me out please.
Here is the code:
{////<<head>
<title>IIBO Submit Page</title>...
|
by: tyler_durden |
last post by:
thanks a lot for all your help..I'm really appreciated...
with all the help I've been getting in forums I've been able to continue
my program and it's almost done, but I'm having a big problem that...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: Joner |
last post by:
Hello,
I'm having trouble with a little programme of mine where I connect to
an access database. It seems to connect fine, and disconnect fine, but
then after it won't reconnect, I get the error...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: PEB |
last post by:
POSTING GUIDELINES
Please follow these guidelines when posting questions
Post your question in a relevant forum
Do NOT PM questions to individual experts - This is not fair on them and...
|
by: 2Barter.net |
last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA
Inbox
Reply
Reply to all
Forward
Print
Add 2Barter.net to Contacts list
Delete this message
Report phishing
Show original
|
by: jenipriya |
last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors...
The table structures i hav
Employee (EmpID,...
|
by: tabani |
last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable...
The error arrives from option 'a' it asks...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |