Everything with this particular script was working beautifully until I added lines 65 through 72 to check against existing data. Since I put it in there I get "Warning: Cannot modify header information - headers already sent by ......"
I tried sticking in ob_start and ob_end_flush functions in lots of different places to accomplish an easy fix, but to no avail. I'd love to just be lazy and ignore it since it DOES throw the right error when applicable, however, it also creates the entry in the DB as well and THAT I cannot live with 😕
Anyone have any ideas on this?
<?php
$con = mysql_connect("localhost","db_user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_name", $con);
$uname = $_POST["UName"];
$pwd = $_POST["Pwd"];
$passwd = $_POST["Passwd"];
$fname = $_POST["FName"];
$lname = $_POST["LName"];
$email = $_POST["EAddress"];
$address = $_POST["Address"];
$city = $_POST["City"];
$state = $_POST["State"];
$zip = $_POST["Zip"];
$country = $_POST["Country"];
$month = $_POST["BDayM"];
$day = $_POST["BDayD"];
$year = $_POST["BDayY"];
$agree = $_POST["agree"];
$len_uname = strlen($uname);
$len_passwd = strlen($passwd);
$len_fname = strlen($fname);
$len_lname = strlen($lname);
$len_email = strlen($email);
$len_address = strlen($address);
$len_city = strlen($city);
$len_state = strlen($state);
$len_zip = strlen($zip);
$len_country = strlen($country);
$len_month = strlen($month);
$len_day = strlen($day);
$len_year = strlen($year);
$len_agree = strlen($agree);
$regm = date(m);
$regd = date(d);
$regy = date(Y);
if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $error = true; echo "The email address entered is not valid. Please go back and submit the form again.<br>"; }
elseif($len_uname == 0) { $error = true; echo "The Username field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_passwd < 6) { $error = true; echo "Your password must be at least six characters long. Please go back and submit the form again.<br>"; }
elseif($len_fname == 0) { $error = true; echo "The first name field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_lname == 0) { $error = true; echo "The last name field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_email == 0) { $error = true; echo "The email address field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_address == 0) { $error = true; echo "The address field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_city == 0) { $error = true; echo "The city field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_state == 0) { $error = true; echo "The state field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_zip == 0) { $error = true; echo "The postal code field cannot be blank. Please go back and submit the form again.<br>"; }
elseif($len_country == 0) { $error = true; echo "You must select the country you reside in. Please go back and submit the form again.<br>"; }
elseif($len_month == 0) { $error = true; echo "You must select the month you were born in. Please go back and submit the form again.<br>"; }
elseif($len_day == 0) { $error = true; echo "You must select the day you were born on. Please go back and submit the form again.<br>"; }
elseif($len_year == 0) { $error = true; echo "You must select the year you were born in. Please go back and submit the form again.<br>"; }
elseif($pwd != $passwd) { $error = true; echo "The passwords entered do not match. Please go back and submit the form again.<br>"; }
elseif($len_agree != 3) { $error = true; echo "You must agree to the site terms and conditions in order to register. Please go back and submit the form again.<br>"; }
$q_uname = mysql_query("SELECT * from userinf WHERE UName='$uname'");
if(mysql_num_rows($q_uname) > 0) { $error = true; echo "The Username you have chosen is already in use. Please go back and submit the form with a different Username.<br>"; }
$q_email = mysql_query("SELECT * from userinf WHERE EAddress='$email'");
if(mysql_num_rows($q_email) > 0) { $error = true; echo "An account already exists with the email address you have supplied.<br>"; }
$q_address = mysql_query("SELECT * from userinf WHERE Address='$address'");
if(mysql_num_rows($q_address) > 0) { $error = true; echo "An account already exists with the address you have supplied.<br>"; }
$sql="INSERT INTO table
(UName, Passwd, FName, LName, EAddress, Address, City, State, Zip, Country, BDayM, BDayD, BDayY, RegM, RegD, RegY)
VALUES
(\"".$_POST["UName"]."\",
\"".$_POST["Passwd"]."\",
\"".$_POST["FName"]."\",
\"".$_POST["LName"]."\",
\"".$_POST["EAddress"]."\",
\"".$_POST["Address"]."\",
\"".$_POST["City"]."\",
\"".$_POST["State"]."\",
\"".$_POST["Zip"]."\",
\"".$_POST["Country"]."\",
\"".$_POST["BDayM"]."\",
\"".$_POST["BDayD"]."\",
\"".$_POST["BDayY"]."\",
$regm,
$regd,
$regy)";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con);
header("Location: http://blah.com/blah.html");
?>