I am stuck with a problem , I am getting an "failed" result while submitting the signup form, I don't know where I am wrong, please help.
ajaxrequest.js
function addStu() {
var stuname = $("#stuname").val();
var stuemail = $("#stuemail").val();
var stupass = $("#stupass").val();
$.ajax({
url:'Student/addStudent.php',
method:"POST",
dataType: "json",
data:{
stuname : stuname,
stuemail : stuemail,
stupass : stupass,
},
success:function(data){
console.log(data);
if(data == "OK"){
$('#successMsg').html("<span>Registration Successfull!</span>")
}
else if(data === "failed"){
$('#successMsg').html("<span> Unable to Register!</span>")
}
},
});
}
addStudent.php
This is the addstudent.php form where wrote i insert data code
<?php
include_once('../dbconnection.php');
if(isset($_POST['stuname']) && isset($_POST['stuemail']) && isset($_POST['stupass']))
$stuname = $_POST['stuname'];
$stuemail = $_POST['stuemail'];
$stupass = $_POST['stupass'];
$sql = "INSERT INTO student(stu_name, stu_email, stu_pass) VALUES('$stuname','$stuemail','$stupass')";
if( $conn->query($sql)== TRUE){
echo json_encode("OK");
}
else{
echo json_encode("failed");
}
?>