This is probably very simple, but I'm really in over my head. Basically, I have a form with one input: email, and a submit button. This was not done by me so I understand very little of it. I tried to look up the .ajax jQuery command, but it still makes no sense.
Basically, here is what I have on the index.php.
The JS and HTML:
<!-- Subscription -->
<script>
$(function() {
$('form input.submit').click(function (event) {
event.preventDefault();
event.returnValue = false;
$.ajax({
type: 'POST',
url: 'subscribe.php',
data: {email: $('form input[type=email]').val()},
success: function(data) {
if (data == 'successful') {
$('#subscribe_status').html('Thanks for subscribing! We will let you know.').slideDown();
} else if (data == 'already_subscribed') {
$('#subscribe_status').html('This email is already subscribed.').slideDown();
} else if (data == 'invalid_email') {
$('#subscribe_status').html('This email is invalid.').slideDown();
} else {
$('#subscribe_status').html('Something went wrong. Please try again.').slideDown();
}
},
error: function () {
$('#subscribe_status').html('Subscription is not available.').slideDown();
}
});
});
});
</script>
<form action="#">
<input type="email" value="Your e-mail address..." onfocus="value=''" />
<input type="submit" class="submit" value="Notify me" />
</form>
Subscribe.php
include 'go.php';
$email = $_POST['email'];
$ip=$_SERVER['REMOTE_ADDR'];
$timestamp = date("m/d/y H:i A");
mysql_query("INSERT INTO subscribers (ip, email, timestamp) VALUES (INET_ATON('$ip'), '$email', '$timestamp') ") or die(mysql_error());
I basically just keep getting "Something went wrong. Please try again."
dataparameter will be whatever your PHP file echo'd. So if you echo nothing on successful data entry (which it looks like might be happening), then the JavaScript will think that something went wrong. Can you confirm that the data is actually being entered into the database?$ipand executing the SQL query by hand. What error message(s) do you get when you do that?