Jump to content

about Begin, Commit and RollBack in Core PHP Mysqli


SagarGavali

Recommended Posts

In my one php registration form i have generated one code automatically and if multiple users registering on form then each registration should be on different code but right now its not working. Right now if only two users using same form, still it is registering same code for two records. Please tell me how to make it perfect for multiple users??? Following i am sharing my core php code, Please tell me whether it is correct or wrong and tell me the changes also: 

<?php
      include_once('dbConnect.php');

      // Insert
     if(isset($_POST['Submit']))
    {                                
    $url = trim($_POST['URL']);                    
    $ptype = trim($_POST['HID']);
                
    $AcName = trim($_POST['LName']);
    $Description = trim($_POST['descr']);                
                
    //*** Start Transaction ***//
    mysqli_query($dbCon,"BEGIN");
                
    echo "<script> alert('Function Called!!!'); GenerateCode(); </script>";   // This is Javascript function called for code Generartion again    
                
    $Code =  trim($_POST['code']);    // Posted that Assigned code to variable    

// Insert Query                
        $Query = "insert into ma_cal(CAL_CahId,CAL_Code,CAL_Name,CAL_Description) values ('$ptype','$Code','$AcName','$Description')";
                                
   $Result = @mysqli_query($dbCon,$Query);
                                                
       if(!$Result)
       {
      //*** RollBack Transaction ***//                         
            mysqli_query($dbCon,"ROLLBACK");

    $DB_Error = "Database Error => ".mysqli_error($dbCon); 
        }            
        else
        {
    //*** Commit Transaction ***//                         
         mysqli_query($dbCon,"COMMIT");                    
                        
    $InsertSuccess = "Done";
        }
    
}  // If end

?>


// This is Javascript function for Code Generation which i have called in <Head> tag

 <script type="text/javascript">
    function GenerateCode()
    {
    var id = document.getElementById("HeadAcc").value;
            
      var dataString = 'PID='+ id;
        
    $.ajax
    ({
        type: "POST",
        url: "get_LedgerCode.php",
       data: dataString,
       cache: false,
       success: function(html)
       {                    
         $("#GotCode").html(html);
       } 
    });
    
   }    
    </script>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.