Note that there are some explanatory texts on larger screens.

plurals
  1. POAdds same record multiple times to database instead of just once
    primarykey
    data
    text
    <p>I have an issue with php script, it adds more records than it suppose to. I have big table with several "subtables" with people's salaries and its distribution:</p> <h1>Name # PayRate # Distribution # Annual</h1> <p>John Smith # 10,000 # 20.00% # 50,000 # edit # delete<br /> Peter Pan # 100,000 # 100.00% # 100,000 # edit # delete<br /></p> <h2>Add new person</h2> <p>When you click on new person, form pop up, you type all information, add person to database, ajax returns information and add person to the end of the list. here is the problem, when I click in one "subtable" add person, it adds one person and prints correctly, but when I go to second "subtable", and add a person, it will add person two times (insert two same records to database), if I click add person on third "subtable" it will add one record three times... It should add record only once. Here is my js script:</p> <pre><code>$('.addbtt').on('click', function(){ value= ""; document.getElementById("updform").reset(); var glnumber = $(this).parent().parent().find('#glno').text(); var objid = glnumber.substring(7,12); value += glnumber.substring(10,12); if(objid=='51001'){ $('.modal-title').html("Add person - Full time"); $('#glnumber').empty().val(glnumber); }else if(objid=='51002'){ $('.modal-title').html("Add person - Part time"); $('#glnumber').empty().val(glnumber); }else if(objid=='51009'){ $('.modal-title').html("Add person - GA"); $('#glnumber').empty().val(glnumber); }else if(objid=='51010'){ $('.modal-title').html("Add person - GE"); $('#glnumber').empty().val(glnumber); }; $('#updform').submit(function(){ var formData = $(this).serialize(); $.post('includes/updatesal.php',formData,processData); function processData(data){ if(value == 01){ $('#addperson1').before(data); }else if(value == 02){ $('#addperson2').before(data); }else if(value == 09){ $('#addperson3').before(data); }else if(value == 10){ $('#addperson4').before(data); }else{ alert("Your are doing something you shouldn't! :)") }; }; //end of processData return false; }); }); </code></pre> <p>I think the problem is with my "add person button" because it adds also two records to the database. Here is my php function:</p> <pre><code>$insertSQL1 = "INSERT INTO salaries (gl_number,name,pay_rate,distribution,annual) VALUES ('".$glnumber."','".$name."','".$payRate."','".$dist."','".$annual."')"; $insertSQL1 .= "; SELECT SCOPE_IDENTITY() AS RECORD_ID"; $stmt1 = sqlsrv_query(Database::GetInstance()-&gt;databaseConnection, $insertSQL1); # IF THERE IS AN ERROR if(!$stmt1){ echo "Error"; }else{ $id = Database::GetInstance()-&gt;LastInsertId($stmt1); } # IF ALL QUERIES WERE SUCCSESSFUL, COMMIT THE TRANSACTION, OTHERWISE ROLLBACK if($stmt1 &amp;&amp; !$errors){ sqlsrv_commit(Database::GetInstance()-&gt;databaseConnection); # FREE THE STATEMENT Database::GetInstance()-&gt;FreeDBStatement($stmt1); </code></pre> <p>I am trying to figure this out for a week now, can anybody help?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload