How to insert php ajax textbox value into mysql database table?
90
I have ajax call in my index page, when the user enter a username into the text box it's need to insert into a mysql db table,can't find a way to do it?
This is my code
$(document).ready(function () {
$('#enter_email_id').change(function () {
var str = $('#enter_email_id').val();
var webFormURL = "get_acc_info.php?q=" + str;
$.ajax({
url: webFormURL,
async: false,
success: function (response) {
$('.test_acc').html(response);
}
});
This is insert db php page
<?php
session_start();
$_SESSION["username"];
function insert_Details(){
include 'Db_Connection.php';
$sql="INSERT INTO search(searcher,searched_time,searched_email)
VALUES('$_SESSION[username]',".NOW().",'$_POST[searched_email]')";
}
?>
Answer
Solution:
for security reasons you should use
mysqli_real_escape_string()
for input values. I've got to fix your code, but you should replace$_SESSION["username"]
value with what you want, use this code:JavaScript:
PHP: