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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探