jquery - Inserting values to database while typing -
i have task.i want insert data database while typing values in textbox.... don't know possible.is possible. example appreciated.
thanks in advance
yes, possible that. here example you, in php way. can change jsp using references.
html
<input type="text" id="hey">
jquery
$('#hey').on('keyup', function(){ $.ajax({ type : 'post', url : 'insertdata.php', // --> server side code insert data db data : { val : $(this).val() }, success : function(msg){ // msg -> return server side // code in success // if success print out 'new record created successfully' // if error print out 'error occured' console.log(msg); } }); });
php - insertdata.php
<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "mydb"; // create connection $conn = new mysqli($servername, $username, $password, $dbname); $sql = "insert comment (mytext) values (".$_post['val'].")"; if ($conn->query($sql) === true) { echo "new record created successfully"; } else { echo "error occured"; } $conn->close(); ?>
Comments
Post a Comment