View Full Version : Php Q..

03-28-2011, 03:25 PM
Good morning guys: I have this php script to send data into a db and the e-mail needs to be filled in. The form works perfect and if user fails to include an email the browser will open a new page to tell user to input an e-mail. My question is how can I make script tell user to input an email inside the same form. In other words, instead of opening a new page? Thanks..Here's the script..

$con = mysql_connect("localhost","",""); //Replace with your actual MySQL DB Username and Password
if (!$con)
die('Could not connect: ' . mysql_error());
// Where to redirect after form is processed.
$url = '';

mysql_select_db("db", $con); //Replace with your MySQL DB Name

$name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file
$genre_1=mysql_real_escape_string($_POST['genre_1']); //This value has to be the same as in the HTML form file

function is_valid_email($e_mail) {
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~]+@([0-9.]+|([^\s]+\.+[a-z]{2,6}))$#si', $e_mail);

if (!is_valid_email($e_mail)) {
echo 'Sorry, you must enter an e-mail. Please go back and input an e-mail';

$sql="INSERT INTO (db) (name,e_mail,gender,age,genre_1,genre_2,genre_3,ge nre_4,genre_5,genre_6,time,feedback)

VALUES ('$name','$e_mail','$gender','$age','$genre_1','$g enre_2','$genre_3','$genre_4','$genre_5','$genre_6 ','$time','$feedback')"; /*form_data is the name of the MySQL table where the form data will be saved.

name and email are the respective table fields*/
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
echo "ok";
echo "Thank you for submitting.";
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

03-29-2011, 01:34 AM
use javascript on the form for that, being client side 'validation" using onSubmit it will validate before submitting