Ajax Crud Oparetion (Only Insert Code "create") | PHP | Jquery | Ajax | CODE
index.php(Frontend & ajax)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form id="aj">
Name :<input type="text" name="u_name">
Mobile :<input type="text" name="u_mob">
<button type="button" onclick="user_submit();">SEND</button >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function user_submit()
{
var send = new FormData(aj);
// console.log(send);
$.ajax({
data : send,
type : "POST",
url : "backii.php",
processData : false,
contentType : false,
success :function(response)
{
console.log(response);
}
})
}
</script>
</body>
</html>
backii.php(Backend Code)
<?php
//testing successfull
// echo "successfull Shuvadeep";
$conn = mysqli_connect("localhost","root","","practice_ajax");
if (!$conn)
{
echo "ERROR in Data Insertion";
}
$v_name = $_POST["u_name"];
$v_mob = $_POST["u_mob"];
// echo $v_name;
// echo $v_mob;
// exit();
$query = "INSERT INTO ajax_table (DB_name,DB_password) VALUES('$v_name','$v_mob')";
$connection = mysqli_query($conn, $query);
if ($query)
{
echo "inserted";
}else{
echo "not Inserted";
}
?>
Comments
Post a Comment