There is an Ajax request that adds entries to the database.
How can I get the id of the newly added record in the database and record this id in response?
$.ajax({ type: "POST", url: 'send.php', data: {name:name}, success: function(response){ if(response == 0){ $("#section").val(""); $("#resp").append('<div id="resp">'+name+'</div>'); } } });
file send.php
$name = $_POST['name']; $insert = mysqli_query($connection,"INSERT INTO section_list (section) VALUES ('$name')"); if($insert == true){ echo 0; }else{ echo 1; }
echo
, but the value of $ id, but on the js side, check: if it is non-zero, then everything is ok and inresponse
the id number of the added line. - Visman