内部服务错误POST 500 AJAX,jQuery + PHP

时间:2017-04-16 06:54:54

标签: php server runtime-error

我一直在尝试调试,但我无法让内部错误消失。

此代码的功能是它将从表单接收电子邮件并通过数据库运行它以检查数据库中是否已有电子邮件。

如果有,它将显示错误消息vendor.js:9566 POST http://snacktally.com/emailcheck.php 500(内部服务器错误)。

这里是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);
    }
  });
});

这里是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';
}
?>

2 个答案:

答案 0 :(得分:0)

$_POST('email')更改为$_POST['email']

阅读this以调试代码

答案 1 :(得分:0)

将$ _POST(&#39;电子邮件&#39;)替换为$ _POST [&#39;电子邮件&#39;]