I'm simply trying to read in a field from a text box, pass the value via ajax to PHP and then store the data in a mysql table. The table is already set up and ready to go, all I need is to insert values.
Here is my js file
var address = $("input#email").val();
//If submission is valid
if(submitForm == "true"){
$.ajax({
url: "bin/process.php",
type: "POST",
data: {email: address},
success: function(response) {
$('#message').html(response);
}
});
return false;
}
And then my PHP looks like this
<?php
function process($email){
//Connect to the database
$con = mysql_connect('localhost', 'root', '') ;
if(!$con){
retun mysql_error();
}
//Insert Data into the Table
$sql = 'INSERT INTO Users(email) VALUES ('$email')' ;
$query = mysql_query($sql, $con)
if(!$query){
return mysql_error();
}
return "Thank you for your submission!";
}
echo process(trim($_POST['email']));
?>
Right now I am getting this error
Parse error: syntax error, unexpected T_STRING /opt/lampp/htdocs/mysite/bin/process.php on line 3
So it appears that I am not passing the address value correctly, but I cannot figure out why. For reference I was following the instructions on this post: Jquery ajax call from javascript to PHP
I don't quite understand the last echo line, but I tried multiple methods, and they all gave me the same error.
Thanks in advance!