Please help....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Paterson

    Please help....

    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");
    ?>


  • lazo

    #2
    Re: Please help....

    "Matthew Paterson" <mpaterso@telus .net> wrote in message news:<3Jdxb.338 28$oN2.6392@edt nps84>...[color=blue]
    > 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");
    > ?>[/color]

    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.

    Comment

    • Pedro Graca

      #3
      Re: Please help....

      lazo wrote:[color=blue]
      > [...]
      > echo "[" . $sql99 . "]";
      > echo "<br>\n";
      > echo "[" . $sql2 . "]";
      >
      > and then chech in html source "view source", if they are exactly the
      > same.[/color]

      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 =--

      Comment

      • Chung Leong

        #4
        Re: Please help....

        The problem is in here
        [color=blue]
        > // strip off last ,
        > $length = strlen($ids);
        > $ids[$length-1] = "";
        >
        > $length = strlen($values) ;
        > $values[$length-1] = "";[/color]

        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,di vision,province ,filetitle,air, water,sewage,pt tw,partVIII,par t
        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" <mpaterso@telus .net> wrote in message news:<3Jdxb.338 28$oN2.6392@edt nps84>...[color=blue]
        > 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");
        > ?>[/color]

        Comment

        • Matthew Paterson

          #5
          Re: Please help....

          YOU ARE A ROCKSTAR!!!

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

          You made my week!!!

          Thanks again!!!!


          "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
          news:a164f4b5.0 311270638.575dc 3a2@posting.goo gle.com...[color=blue]
          > The problem is in here
          >[color=green]
          > > // strip off last ,
          > > $length = strlen($ids);
          > > $ids[$length-1] = "";
          > >
          > > $length = strlen($values) ;
          > > $values[$length-1] = "";[/color]
          >
          > 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
          >[/color]
          Cards(active,di vision,province ,filetitle,air, water,sewage,pt tw,partVIII,par t[color=blue]
          > 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" <mpaterso@telus .net> wrote in message[/color]
          news:<3Jdxb.338 28$oN2.6392@edt nps84>...[color=blue][color=green]
          > > Can anyone tell me why in the code below the sql execute that uses[/color][/color]
          $sql99[color=blue][color=green]
          > > does not work while the one with $sql2 works. $sql99 is exactly the same[/color][/color]
          as[color=blue][color=green]
          > > $sql2 when printed out.
          > >
          > > I get an error saying:
          > > Warning: (null)(): Invoke() failed: Exception occurred. Source:[/color][/color]
          Microsoft[color=blue][color=green]
          > > JET Database Engine Description: Syntax error in INSERT INTO statement.[/color][/color]
          in[color=blue][color=green]
          > > 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[/color][/color]
          #")[color=blue][color=green]
          > > $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 .[/color][/color]
          ")";[color=blue][color=green]
          > > $sql99 = trim($sql99);
          > >
          > >
          > >
          > > // PHP db connection
          > > $sql2 = "INSERT INTO
          > >[/color][/color]
          Cards(active,di vision,province ,filetitle,air, water,sewage,pt tw,partVIII,par t[color=blue][color=green]
          > > 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");
          > > ?>[/color][/color]


          Comment

          Working...