I have a php script:
echo "<td> <select id='ocenka-day".$chislo."-" . $rowstudentlist['id'] . "'> <option disabled selected></option> <option value='0'>Н</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> </select> <script type='text/javascript' > $( document ).ready(function() { $('#ocenka-day".$chislo."-".$rowstudentlist['id']."').change(function(){ var value = $(this).val(); var vstudiin = '".$rowstudentlist['iin']."'; var vday = ".$chislo."; var vprepodiin = '".$iin."'; var vdisid = $selectdis; var vmonth = $selectmonth; var vgr = $selectgr; var vsemestr = $semestr; $.ajax({type:'POST', url:'my-journals-save.php', data:{ocenka:value,day:vday,studiin:vstudiin,prepodiin:vprepodiin,disid:vdisid,month:vmonth,gr:vgr,semestr:vsemestr}, dataType:'html', success:function(){ } });});}); </script> </td>";
The second script to insert into the table (my-journals-save.php):
$studiin=$_POST['studiin']; $ocenka=$_POST['ocenka']; $day=$_POST['day']; .... require($_SERVER['DOCUMENT_ROOT'].'/connect.php'); $sql = pg_query($dbconn,"INSERT INTO journal (disid,disname,monthnumber,monthname,semestr,prepodiin,studiin,gr,day,ocenka,ugods,ugodp,ocenkadat) VALUES ($disid,'$disname',$month,'$monthname',$semestr,'$prepodiin','$studiin','$gr',$day,$ocenka,$ugods,$ugodp,'$dat')");
Everything would be fine, but when inserting, the database is placed twice at once, as I understand the script works two times. even the seconds are the same, only the IDs are different The script hangs only once, the script is not duplicated, the ID of the elements also read similar questions in stackoverflow :)