内部服务器错误POST 500 AJAX,jQuery + PHP
问题描述:
I've been trying to debug all day and I cannot get the internal error to disappear.
The functionality of this code is that it will take in an email from the form and run it through the database to check if there is already an email in the database.
If there is, it will display an error message vendor.js:9566 POST http://snacktally.com/emailcheck.php 500 (Internal Server Error).
Here's the jQuery:
$("#userform").submit(function(event) {
var emailtext = {
email: $("#Email").val();
};
$.ajax({
type: "POST",
url: "emailcheck.php",
data: emailtext,
dataType: 'json',
success: function(response, textStatus, req) {
if (response == '1') {
//default action
} else {
$("#emailField").css("border-left", "2px solid #ff3333");
$("#passField").css("border-left", "2px solid #FCFCFC");
$("#passVerField").css("border-left", "2px solid #FCFCFC");
$("h1").text("Email Taken").css("color", "#ff3333");
event.preventDefault();
}
},
error: function(xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(xhr.responseText);
console.log(thrownError);
}
});
});
and here's the PHP
<?php
#sql_host, user pass and db defined up here
$con = mysqli_connect($sql_host,$sql_user,$sql_pass,$sql_db);
#obtains the email from the php file
if(isset($_POST('email')))
{
$email = $_POST('email');
#runs it through the database
$emailver = "SELECT `Email` FROM `SnackTally`.`User` WHERE `Email` =
'$email'";
if($select = mysqli_query($con, $emailver)){
#output 0 = false, not a valid email
if(mysqli_fetch_assoc($select) > 0)
{
#$emailErr = "Email already exists";
mysqli_free_result($select);
mysqli_close($con);
echo '0';
}
else
{
mysqli_free_result($select);
mysqli_close($con);
echo '1';
}
}
}else{
mysqli_close($con);
echo '0';
}
?>
答
Replace $_POST('email') to $_POST['email']