I have a problem with a signup option that I’ve created on my website. For my signup option, I have followed this tutorial exactly: https://code.tutsplus.com/tutorials/building-a-sleek-ajax-email-signup-form--net-13645
It worked like a charm on my test website, but now that I’ve moved everything to another server, I get two different types of error messages.
The error concerns the following line in my javascript file:
var responseData = jQuery.parseJSON(data),
This is what Safari, Firefox and Opera are telling me. And then Chrome is also reporting this error:
Is this maybe because mysql functions have been removed in PHP7? My new server uses PHP 5.6 though… My PHP looks like this at the moment:
<?php
if(isset($_GET['action'])&& $_GET['action'] == 'signup'){
mysql_connect('localhost:3306','db_username','db_password');
mysql_select_db('db_name');
//sanitize data
$email = mysql_real_escape_string($_POST['signup-email']);
//validate email address - check if input was empty
if(empty($email)){
$status = "error";
$message = "You did not enter an email address";
}
else if(!preg_match('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/', $email)){ //validate email address - check if is a valid email address
$status = "error";
$message = "Invalid email address";
}
else {
$existingSignup = mysql_query("SELECT * FROM signups WHERE signup_email_address='$email'");
if(mysql_num_rows($existingSignup) < 1){
$date = date('Y-m-d');
$time = date('H:i:s');
$insertSignup = mysql_query("INSERT INTO signups (signup_email_address, signup_date, signup_time) VALUES ('$email','$date','$time')");
if($insertSignup){
$status = "success";
$message = "You have been signed up";
}
else {
$status = "error";
$message = "Ooops, there has been a technical error";
}
}
else {
$status = "error";
$message = "This email address has already been registered";
}
}
//return json response
$data = array(
'status' => $status,
'message' => $message
);
echo json_encode($data);
exit;
}
?>
Would I have to rewrite this with the new mysqli_connect()? How would I have to do that? But then I’m still left with first problem… Does anyone have an idea how I can solve these two problems? Thank you very much!