Insert new records into database using jQuery in PHP web application. Submit all records into MySQl table without page reload.
Script:
<script type="text/javascript"> $('#submit_data').click(function(){ $.ajax({ type: 'post', url: 'insert.php', data: {name:$('#name').val(), price:$('#price').val()}, success: function(result){ if(result=='1'){ alert("Insert Successful"); }else{ alert("Insert Error!!"); } } }); }); </script>
PHP:
<?php $name=$_POST['name']; $price=$_POST['price']; mysqli_query($mysqli,"INSERT INTO `table name`(`name`,`price`)VALUES('$name','$price')"); ?>
Question and answer is powered by AnsPress.io