Sign Up Form Trouble?



I’m trying to create a php sign up form and I’m having some trouble with it’s “Error Handling”

When I am trying to make it have required fields, check and confirm the email addresses,passwords, and the desired username. (I haven’t added in the desired user name, yet)

The problem I’m having is that when I test the script it doesn’t do… Well any of it. It will allow me to leave all the fields blank, have different email addresses/passwords, and it still posts to my database. I am not sure where exactly I am going wrong with the script but it seems like I’m having trouble just about everywhere.

Here is my code

$companyname= “”;
$state= “”;

if (isset ($_POST[‘companyname’])){

$companyname= $_POST['companyname'];
$dropship=$_POST['dropship'	];


$companyname=strip_tags ($companyname);

//Connect To Dataebase

//Check For Duplicate Emails

$sql_email_check = mysql_query("SELECT email from members WHERE email='$email'");
$emailcheck =mysql_num_rows($sql_email_check);

if ($emailcheck > 0){ 
          $errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our database. Please use another.<br />"; 
//Error Handling Missing Data
if ((!$companyname) || (!$companytype) || (!$dropship) || (!$country) ||(!$state) || (!$zip) || (!$username) || (!$email) || (!$email2) ||(!$password) || (!$password2)){
$errorMsg = 'ERROR: You did not submit the following required information:<br /><br />';

	$errorMSG = 'Comany Name <br />';		
	$errorMSG= 'State/Province <br />';	

	$errorMSG="Zip Code <br />";	

	$errorMSG="Desired User Name <br />";	

	$errorMSG="Email Address <br />";	

	$errorMSG="Confirm Email Address <br />";
	$errorMSG="Password <br />";	
	$errorMSG="password2 <br />";		

else if($email !=$email2){
	$errorMSG="ERROR: Your Email Addresses Didn't Match <br />";
	print $errorMsg;	
else if($password != $password2){
	$errorMSG="ERROR: Your Passwords Don't Match <br />";	
else if ($email_check > 0){
	$errorMSG="ERROR: Your Email Address Is Already In Use<br />";	

$companyname=mysql_real_escape_string ($companyname);

 //Password Hash

$sql= mysql_query("INSERT INTO members (companyname,companytype,dropship,country,state,zip,phone,username,website,youtube,email,password)
or die(mysql_error());


	$errorMSG="Field Marked With [*] are required";



here is fully defined login and sign up script check it out


why are you adding this at the beginning?
$companyname= “”;
$state= “”;

also I don’t see anywhere, where you actually die $errorMSG;, you need to add something like if($errorMSG){die $errorMSG;}


I put that at the start of the code because I use it to remember what someone has typed in if they get an error. I got the code going I had a misplaced } closing my checks early resulting in unexpected behavior. I can’t see how much of the script I posted earlier but in the form fields value I use [php]<?php echo "$field_var"?> [/php] this allows the script to save any text the user types in so they don’t have to type it in again if there is an error.

If I don’t have the $var=""; at the beggining I get an undefined variable error, only inside my test environment tho.