doucheng7808 2017-04-16 06:54
浏览 88
已采纳

内部服务器错误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';
}
?>
  • 写回答

2条回答 默认 最新

  • doutai1509 2017-04-16 07:00
    关注

    change $_POST('email') to $_POST['email']

    Read this for debugging your code

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突