Results 1 to 6 of 6

Thread: [RESOLVED] two times insert into doesn't work

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    right here
    Posts
    87

    Resolved [RESOLVED] two times insert into doesn't work

    Hello All,

    In my php pages I make a sql string:
    Code:
    INSERT INTO TBL_Magazijn_Locatie_Bezetting ( MagLocBezetId, MagLocId, Art_Ref_Fabr, Art_ArtSrt_Nr, Art_BCode, Art_Oms, Aant, txtDatum, Art_Nr, SerieNr )
    VALUES (3192, 415, 'DA150', 1, '� 33180', 'ONDERBOUWDAMPK MIELE 1M RVS', 1, '22/10/2009', '33180', '0');
    And php runs this sql string into the database, it works perfect.
    But when the user inserts the same product again it says 'saved' but it isn't saved into the msSQLserver database.
    No errors.
    When the user inserts another product it works perfect.
    When the user inserts the first product again it works perfect.
    It doesn't work with two times the same sql string.

    When I run the sql string in access it works, two times, twenty times.
    There is a column 'ID' which has a 'key' and 'autonumber' but this column isn't inserted. (as it shouldn't be)
    The value of Art_BCode--> '� 33180' is not the problem as I have removed the '�' and still it doesn't work two times after each other.

    The code is very long but this last bit is were the sql string is made and used.
    The code before this is all about filling the variables with the right information.


    if ($ErrorId == 0)
    {
    switch ($FO)
    {
    case 0:
    $Query_Insert = "INSERT INTO TBL_Magazijn_Locatie_Bezetting
    (MagLocBezetId, MagLocId, Art_Ref_Fabr, Art_ArtSrt_Nr, Art_BCode, Art_Oms, Aant, txtDatum, Art_Nr, SerieNr)
    VALUES ($MagLocBezetId, $MagLocId, '$Art_Ref_Fabr', 1, '$Art_BCode', '$Art_Oms', $Aantal, '$today', '$Art_Nr', '$SerieNr')";
    break;
    case 1:
    $Query_Insert = "INSERT INTO TBL_Magazijn_Locatie_Bezetting
    (MagLocBezetId, MagLocId, Art_Ref_Fabr, Art_ArtSrt_Nr, Art_BCode, Art_Oms, Aant, txtDatum, Art_Nr, Info_Srt, FactHfd_Nr, FactHfd_Klnt_Alias, FactHfd_Klnt_Naam, FactHfd_Klnt_Nr, FactHfd_Lev_Dat, SerieNr)
    VALUES ($MagLocBezetId, $MagLocId, '$Art_Ref_Fabr', 1, '$Art_BCode', '$Art_Oms', $Aantal, '$today', '$Art_Nr', '$Info_Srt', '$FactHfd_Nr', '$TMP_Klnt_Alias', '$TMP_Klnt_Naam', '$TMP_Klnt_Nr', '$TMP_Lev_Dat', '$SerieNr')";
    break;
    case 2:
    $Query_Insert = "INSERT INTO TBL_Magazijn_Locatie_Bezetting
    (MagLocBezetId, MagLocId, Art_Ref_Fabr, Art_ArtSrt_Nr, Art_BCode, Art_Oms, Aant, txtDatum, Art_Nr, Info_Srt, FactHfd_Nr, FactHfd_Klnt_Alias, FactHfd_Klnt_Naam, FactHfd_Klnt_Nr, FactHfd_Lev_Dat, SerieNr)
    VALUES ($MagLocBezetId, $MagLocId, '$Art_Ref_Fabr', 1, '$Art_BCode', '$Art_Oms', $Aantal, '$today', '$Art_Nr', '$Info_Srt', '$FactHfd_Nr', '$TMP_Klnt_Alias', '$TMP_Klnt_Naam', '$TMP_Klnt_Nr', '$TMP_Lev_Dat', '$SerieNr')";
    break;
    }

    //echo $Query_Insert;

    $result = odbc_do($connection, $Query_Insert);
    if ($result == true)
    {
    if (AantalAanpassen($MagLoc) == true)
    {
    echo "Is opgeslagen";
    }
    else
    {
    echo "Er is een fout opgetreden bij het opslaan in de functie AantalAanpassen()";
    }
    }
    else
    {
    echo "Er is een fout opgetreden bij het opslaan: " . $Query_Insert;
    }
    }

    odbc_close($connection);

    //______________________________________________________________________________
    //
    Thanks,
    Brian
    Last edited by brianbaart; Oct 22nd, 2009 at 04:49 AM. Reason: adding the 'save' php code. Brian
    If Not Now Then When

    If Not Here Then Where

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: two times insert into doesn't work

    make sure you're echoing out the query the second time you're trying to run it; try running only that query through access (assuming you haven't). you should also try using odbc_errormsg() to see what the actual error is, if there is one.

    I won't be able to test this to help you, so try those things for now!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    right here
    Posts
    87

    Re: two times insert into doesn't work

    Dear Kows,

    Thank you for your quick respons.

    The sql string is each time the same. Although it is commented now in the code.
    I have ran the sql string in access and it works each time.

    But for your second remark: I take it that this would work beter?

    Code:
      
    $query = odbc_prepare($connection, $Query_Insert);
    $result = odbc_execute($query);
    
    if ($result == false)
    echo odbc_errormsg($connection);
    else
    continue with code
    Thanks for the answer.
    I will try this tomorrow or on monday.
    Brian
    If Not Now Then When

    If Not Here Then Where

  4. #4
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564

    Re: two times insert into doesn't work

    Verify MagLocBezetId is in fact a new ROW ID and not the old one.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    right here
    Posts
    87

    Re: two times insert into doesn't work

    Thank you for your answer but MagLocBezetId is not the 'key' and not the 'auto number'.
    It is a manual ID (meaning I have to fill it with the last used ID and add one myself).
    The actual ID (which is the 'key' and has 'autonumber') isn't filled by this sql string and shouldn't be)
    I have no power over the database, otherwise I would have used MYSQL for sure.

    Brian
    If Not Now Then When

    If Not Here Then Where

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    right here
    Posts
    87

    Re: two times insert into doesn't work

    Found it:

    In the adress: new.php?var1=100,var2=200
    I didn't include a random number.

    Because the string was the same than the last one something along the way must be thinking that the string shouldn't be aloud.

    So by adding a random number at the end of the string I solved that.

    Thanks for everyone the help.
    If Not Now Then When

    If Not Here Then Where

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width