0

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';
}
?>
nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
  • Getting a 500 error means something is wrong with your PHP code (and not caused by the Javascript portion). It would be really helpful to see the specific error that your server is logging when you POST to that URL. It will explain exactly where in your PHP code things are breaking. – supersam654 Apr 16 '17 at 13:10

2 Answers2

0

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

Read this for debugging your code

Community
  • 1
  • 1
ashkufaraz
  • 5,179
  • 6
  • 51
  • 82
0

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

prashant
  • 21
  • 2