/    Sign up×
Community /Pin to ProfileBookmark

mysql connection with alert / no redirect

Hi guys,
I have a form in which the user types its email. The email is then inserted in a mysql db using a php file.
[B]Form code:[/B]
<form name=”frm” method=”post” action=”newsletter.php” onSubmit=”return ValidateForm()”>
<input type=”text” name=”email”>
<br/>
<input type=”submit” name=”Submit” value=”Enviar”>
</form>
[B]
PHP file code:
[/B]

<?php
$con = mysql_connect(“localhost”,”user”,”pass”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“db”, $con);
$sql=”INSERT INTO newsletter (email)
VALUES
(‘$_POST[email]’)”;
if (!mysql_query($sql,$con))
{
die(‘Error: ‘ . mysql_error());
}
echo “Thank you”;
mysql_close($con)
?>

Fortunetly everything is working fine with regards to the db connection, but the browser is directed to the php file and shows the echo “Thank you”;
Want I need to do is rather than being redirected to the php file, just to show something like an alert (e.g. “Your email has been added to our mailing list”) and stay in the same html page where the form is.
Is this doable? And how?

Many thanks
Fred

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 18.2008 — An [url=http://www.google.com/search?q=ajax%2Bphp]AJAX[/url] implementation would be one possibility.
×

Success!

Help @freddygusto spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...