SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Help me!?

  1. #1
    SitePoint Zealot Jafar's Avatar
    Join Date
    Jun 2005
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Help me!?

    forgive my poor english
    i have a problem
    when i for example use several sql query such as insert
    (in one page line45 insert to table1 ,line47 insert data into table2)
    if occur an error between insert1 and insert 2 how i can stop execute insert1
    and dont let insert1 execute?
    or two command execute or anycommant ?
    please help me

  2. #2
    SitePoint Addict
    Join Date
    Sep 2004
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $insert1 = "insert into table1 values(...)";
    ....some code here
    if ($error) $flag = 1;
    else $flag = 0;
    $insert2 = "insert into table2 values(...)";
    if (!$flag) {
    $res1 = mysql_query($insert1) or die(mysql_error());
    $res2 = mysql_query($insert2) or die(mysql_error());
    }


    Execute the two queries when you are sure that the code between them didn't cause any errors.
    If there are errors set $flag = 1 if there aren't set $flag = 0 then check the value of flag. If $flag is 0 execute the queries, if not don't.

  3. #3
    SitePoint Zealot Jafar's Avatar
    Join Date
    Jun 2005
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by acid24ro
    $insert1 = "insert into table1 values(...)";
    ....some code here
    if ($error) $flag = 1;
    else $flag = 0;
    $insert2 = "insert into table2 values(...)";
    if (!$flag) {
    $res1 = mysql_query($insert1) or die(mysql_error());
    $res2 = mysql_query($insert2) or die(mysql_error());
    }


    Execute the two queries when you are sure that the code between them didn't cause any errors.
    If there are errors set $flag = 1 if there aren't set $flag = 0 then check the value of flag. If $flag is 0 execute the queries, if not don't.
    Thanks
    but
    $res1 = mysql_query($insert1) or die(mysql_error());
    $res2 = mysql_query($insert2) or die(mysql_error());
    is it possible that between $res1 and $res2 cause errors for example user disconnecting.

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use Transactions to ensure a group of Statements is executed as a block. Your database will provide documentation on the precise syntax to use to create a Transaction. There are also any number of resources available online to explain the concepts of Transactions much more fully than I could document.

    Is it possible that between $res1 and $res2 cause errors for example user disconnecting.
    The user disconnecting should not cause an error. The script will execute when it is called, regardless of whether the user is connected or not after initialising the script. But other errors may cause problems.


Bookmarks

Posting Permissions

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