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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.