I am adding a form for users to submit to a newsletter.
This sounds like the dumbness "maverick" task, but I need the page to turn over, the script to run the INSERT, and the URL to show something so I can query a variable and add "thanks for submitting...".
I would love to do it in AJAX. So they click "Send", and that little box just changes.
How could this be done in Ajax??
How do I put something in URL on homepage /u=yes ?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do I put something in URL on homepage /u=yes ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I put something in URL on homepage /u=yes ?
I'm trying this, assuming comment.php is the external file to which you are submitting data:
http://malsup.com/jquery/form/
This is my main page:
This is my version, but as newsletter.php:
But it's not submitting anything.
http://malsup.com/jquery/form/
This is my main page:
Code: Select all
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="http://malsup.github.com/jquery.form.js"></script>
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
</script>
<form id='myForm' action='/newsletter.php' method='POST'>
<input type='text' name='email' class='newsletteremail'>
<input type='submit' value='Send'>
</form>
Code: Select all
<?php
$email = $_POST['email'];
$query = ("SELECT * FROM newsletter WHERE email =:email");
$result = $pdo->prepare($query);
$result->execute(array(':email' => $email));
$num_rows = $result->rowCount();
if ($num_rows == 0)
{
$query = "INSERT INTO newsletter =:email";
$result = $pdo->prepare($query);
$result->execute(array(':email' => $email));
}
?>Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I put something in URL on homepage /u=yes ?
Does newsletter.php have any dependencies? Check your error log; looks like the queries might be failing because $pdo isn't defined.