The initial PHP file worked fine, and would display error messages if the user; Entered a password fewer than 6 characters, their passwords didn't match, they left a field blank or if their user/email was already in the database. Now, I have used the exact same code in the new file, and things have gotten rather strange.
At first, it would recreate the HTML form over and over again when 'Submit' was hit and an error occurred, it would display the error, then recreate the HTML form twice if the user/email already existed. I managed to get around that by adding some
Code: Select all
die;Now, I don't know how this 'fixed' it - and by 'fixed' I mean, resolved the previous problem, but created a new one - but I switched the order of my if statements around a bit, so that the validation for blank fields came before the any other validation checks. Now, I tried submitting a blank field, and I got an error telling me that I'd entered one, so, I thought I'd fixed it AGAIN, however, even if I try entering text in the box, I still get the 'Enter Business Name' error which I coded if the Business Name field was left blank.
I just don't know what could be going wrong here. The code worked perfectly when it was in the original PHP file, and all that I've added is the
Code: Select all
ShowForm();Anyway, I'll post the validation part of my code here:
Code: Select all
//check for errors
//check if user/email exists
$userquery = mysql_query("SELECT username FROM southport_businesses WHERE username ='$busname'");
$useravailable = mysql_num_rows($userquery);
$emailquery= mysql_query("SELECT email FROM southport_businesses WHERE email ='$email'");
$emailavailable = mysql_num_rows($emailquery);
if($useravailable > 0)
{
print('Username is taken, please select another');
ShowForm();
die;
}
if($emailavailable > 0)
{
print('E-mail has already been registered');
ShowForm();
die;
}
if($_POST['password1']== "")
{
print("Please fill in password");
ShowForm();
die;
}
if($_POST['busname'] == "");
{
print('Please fill in business name');
ShowForm();
die;
}
if($_POST['password2'] == "")
{
print('Please fill in password');
ShowForm();
die;
}
if($_POST['email'] == "")
{
print('Please fill in email');
ShowForm();
die;
}
if($_POST['PostCode']=="")
{
print('Please fill in postcode');
ShowForm();
die;
}
if($_POST['cont_name']=="")
{
print('Please fill in contact name');
ShowForm();
die;
}
if($_POST['contactnumber']=="")
{
print('Please fill in contact number');
ShowForm();
die;
}
if($_POST['HouseName']=="")
{
print('Please fill in House Number');
ShowForm();
die;
}
if($_POST['HouseName']=="")
{
print('Please fill in road');
ShowForm();
die;
}
if($_POST['HouseName']=="")
{
print('Please fill in town');
ShowForm();
die;
}
//now check passwords match
if($password1 != $password2)
{
print("Passwords don't match!");
ShowForm();
die;
}
//check if passwords meet a minimum length
if(strlen($password1) < 6)
{
print('Password must be 6 characters or longer');
ShowForm();
die;
}
else
{
//ADD DATA TO TABLE