Page 1 of 1

Why isnt all my error checking working?

Posted: Thu Jul 18, 2002 1:58 am
by Apix
From looking at my code would someone be able to tell me why the scrpit only error checks to see if the temp_id is unique and if the passwords match?? it doesnt check if any of the other feilds are filled out like it should. I assume its got something todo with the temp_id uniqueness test because it stopped working after that.. By the way the temp id is like a username that gets changed into the username according to there database position but with RHC at the front.

Code: Select all

<LINK REL="stylesheet" type="text/css" href="main.css" /> 

<?php 
// Membership signup form. html will go here. 
//If form not yet submitted display form. 
if (!isset($submit)) 
&#123; 
?> 
<table cellspacing="5" cellpadding="5" border="0" width="75%" align="center"> 
<form action="<?=$_SERVER&#1111;'PHP_SELF']?>" method="post"> 
<tr> 
<td valign="top"><b><font size="-1">Temporary User ID.</font></b> <font color="red">Do not forget this user id you will need it to complete your signup</td> 
<td><input size="50" maxlength="250" type="text" name="temp_id"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Database Password</font></b></td> 
<td><input size="50" maxlength="250" type="password" name="password"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Verify Database Password</font></b></td> 
<td><input size="50" maxlength="250" type="password" name="verifypassword"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Surname</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="surname"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Firstname</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="firstname"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Middle Name (Not Required)</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="middlename"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Family Members</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="familymembers"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Street Number</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="st_num"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Street Name</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="st_name"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Suburb / Town / City</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="suburb_town_city"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Post Code</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="postcode"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Country</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="country"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Home Phone No.</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="ph_home"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Business Phone No.</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="ph_business"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Mobile Phone No.</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="ph_mobile"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">E-mail Address</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="email"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Occupation</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="occupation"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">Interests</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="interests"></td> 
</tr> 
<tr> 
<td valign="top"><b><font size="-1">(Companies Purchases Only) Name of Nominated Person</font></b></td> 
<td><input size="50" maxlength="250" type="text" name="nominated_person"></td> 
</tr> 
<tr> 
<td><input type="submit" name="submit" Value="Continue"></td> 
</tr> 
</form> 
</table> 
<? 
&#125; 
else 
&#123; 
$errorlist = array(); 
$count = 0; 

$dbconn = mysql_connect("localhost", "user", "pass") or die ("Unable to connect!"); 

mysql_select_db("db", $dbconn) or die ("Unable to select database!"); 

$query = "SELECT temp_id FROM members WHERE temp_id='$temp_id'"; 

$result = mysql_query($query) or die("Query failed at username unique testing stage."); 

$num_rows = mysql_num_rows($result); 

if ($num_rows == 1) &#123; $errorlist&#1111;$count] = "Your Temporary Id is already in use. Please click back and enter another temporary id"; $count++; &#125; 

mysql_close($dbconn); 

if ($password!=$verifypassword) &#123; $errorlist&#1111;$count] = "Your Entered Passwords Do Not Match"; $count++; &#125; 
if (!isset($temp_id)) &#123; $errorlist&#1111;$count] = "Required feild: Temporary ID returned a null value"; $count++; &#125; 
if (!isset($surname)) &#123; $errorlist&#1111;$count] = "Required feild: Surname returned a null value"; $count++; &#125; 
if (!isset($firstname)) &#123; $errorlist&#1111;$count] = "Required feild: Firstname returned a null value"; $count++; &#125; 
if (!isset($familymembers)) &#123; $errorlist&#1111;$count] = "Required feild: Family Members returned a null value"; $count++; &#125; 
if (!isset($st_num)) &#123; $errorlist&#1111;$count] = "Required feild: Street No. returned a null value"; $count++; &#125; 
if (!isset($st_name)) &#123; $errorlist&#1111;$count] = "Required feild: Street Name returned a null value"; $count++; &#125; 
if (!isset($suburb_town_city)) &#123; $errorlist&#1111;$count] = "Required feild: Suburb / Town / City returned a null value"; $count++; &#125; 
if (!isset($postcode)) &#123; $errorlist&#1111;$count] = "Required feild: Postcode returned a null value"; $count++; &#125; 
if (!isset($country)) &#123; $errorlist&#1111;$count] = "Required feild: Country returned a null value"; $count++; &#125; 
if (!isset($ph_home)) &#123; $errorlist&#1111;$count] = "Required feild: Home Phone No. returned a null value"; $count++; &#125; 
if (!isset($email)) &#123; $errorlist&#1111;$count] = "Required feild: E-mail returned a null value"; $count++; &#125; 
if (!isset($occupation)) &#123; $errorlist&#1111;$count] = "Required feild: Occupation returned a null value"; $count++; &#125; 
if (!isset($interests)) &#123; $errorlist&#1111;$count] = "Required feild: Interests returned a null value"; $count++; &#125; 

if (sizeof($errorlist) == 0) 
&#123; 
$dbconn = mysql_connect("localhost", "user", "pass") or die ("Unable to connect!"); 

mysql_select_db("db", $dbconn) or die ("Unable to select database!"); 

$encryptedpassword = md5($password); 

$query = "INSERT INTO members(temp_id, password, surname, firstname, middlename, familymembers, st_num, st_name, suburb_town_city, postcode, country, ph_home, ph_business, ph_mobile, email, occupation, interests, nominated_person) VALUES('$temp_id', '$encryptedpassword', '$surname', '$firstname', '$middlename', '$familymembers', '$st_num', '$st_name', '$suburb_town_city', '$postcode', '$country', '$ph_home', '$ph_business', '$ph_mobile', '$email', '$occupation', '$interests', '$nominated_person')"; 
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); 

echo "Entry successful. <a href=confirmed.php>Click Here To Finish Signup</a>."; 

mysql_close($dbconn); 

&#125; 
else 
&#123; 
echo "The Following Errors Were Incountered:<br />"; 
echo "<ul>"; 
for ($x=0; $x<sizeof($errorlist); $x++) 
&#123; 
echo "<li>$errorlist&#1111;$x]"; 
&#125; 
echo "</ul>"; 
&#125; 
&#125; 
?>

Posted: Thu Jul 18, 2002 2:19 am
by twigletmac

Posted: Thu Jul 18, 2002 2:38 am
by Apix
so i would have something like

if (!isset($_POST['temp_id'])) { $errorlist[$count] = "Required feild: Temporary ID returned a null value"; $count++; }

would that be what the post is saying? sorry i just want to confirm

Posted: Thu Jul 18, 2002 2:57 am
by twigletmac
That's it. BTW, 'feild' should be 'field'.

Mac

Posted: Thu Jul 18, 2002 3:10 am
by Apix
Sweet thanks for the help.. and for finding the spelling error. :D

Posted: Thu Jul 18, 2002 3:44 am
by Apix
ahh.. i spoke to soon. now it reqignises all the feilds as empty.?? any ideas?

Posted: Thu Jul 18, 2002 4:19 am
by twigletmac
Try putting:

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
To see what's being passed by the form.

You should also change the !isset() statements to empty() statements in the validation bits.

The following code seemed to be working for me (of course I can't test the database stuff):

Code: Select all

<link rel="stylesheet" type="text/css" href="main.css" /> 

<?php 
// Membership signup form. html will go here. 
//If form not yet submitted display form. 
if (!isset($_POST&#1111;'submit'])) &#123; 
?> 
<!-- The form as before -->
<?php
&#125; else &#123; 
	echo '<pre>';
	print_r($_POST);
	echo '</pre>';
	$errorlist = array(); 

	$dbconn = mysql_connect("localhost", "user", "pass") or die ("Unable to connect!"); 
	mysql_select_db("db", $dbconn) or die ("Unable to select database!"); 

	$query = "SELECT temp_id FROM members WHERE temp_id='".$_POST&#1111;'temp_id']."'"; 
	$result = mysql_query($query) or die("Query failed at username unique testing stage."); 

	if (mysql_num_rows($result) > 1) &#123;
		$errorlist&#1111;] = "Your Temporary Id is already in use. Please click back and enter another temporary id";
	&#125; else &#123;
		echo 'temp id ok';
	&#125; 

	if ($password != $verifypassword) &#123; $errorlist&#1111;] = "Your Entered Passwords Do Not Match"; &#125; 
	if (empty($_POST&#1111;'temp_id'])) &#123; $errorlist&#1111;] = "Required field: Temporary ID returned a null value"; echo 'no';&#125; 
	if (empty($_POST&#1111;'surname'])) &#123; $errorlist&#1111;] = "Required field: Surname returned a null value"; &#125; 
	if (empty($_POST&#1111;'firstname'])) &#123; $errorlist&#1111;] = "Required field: Firstname returned a null value"; &#125; 
	if (empty($_POST&#1111;'familymembers'])) &#123; $errorlist&#1111;] = "Required field: Family Members returned a null value"; &#125; 
	if (empty($_POST&#1111;'st_num'])) &#123; $errorlist&#1111;] = "Required field: Street No. returned a null value"; &#125; 
	if (empty($_POST&#1111;'st_name'])) &#123; $errorlist&#1111;] = "Required field: Street Name returned a null value"; &#125; 
	if (empty($_POST&#1111;'suburb_town_city'])) &#123; $errorlist&#1111;] = "Required field: Suburb / Town / City returned a null value"; &#125; 
	if (empty($_POST&#1111;'postcode'])) &#123; $errorlist&#1111;] = "Required field: Postcode returned a null value"; &#125; 
	if (empty($_POST&#1111;'country'])) &#123; $errorlist&#1111;] = "Required field: Country returned a null value"; &#125; 
	if (empty($_POST&#1111;'ph_home'])) &#123; $errorlist&#1111;] = "Required field: Home Phone No. returned a null value"; &#125; 
	if (empty($_POST&#1111;'email'])) &#123; $errorlist&#1111;] = "Required field: E-mail returned a null value"; &#125; 
	if (empty($_POST&#1111;'occupation'])) &#123; $errorlist&#1111;] = "Required field: Occupation returned a null value"; &#125; 
	if (empty($_POST&#1111;'interests'])) &#123; $errorlist&#1111;] = "Required field: Interests returned a null value"; &#125; 

	if (sizeof($errorlist) == 0) &#123; 

		$encryptedpassword = md5($password); 

		$query = "INSERT INTO members(temp_id, password, surname, firstname, middlename, familymembers, st_num, st_name, suburb_town_city, postcode, country, ph_home, ph_business, ph_mobile, email, occupation, interests, nominated_person) VALUES('$temp_id', '$encryptedpassword', '$surname', '$firstname', '$middlename', '$familymembers', '$st_num', '$st_name', '$suburb_town_city', '$postcode', 'ry', '$ph_home', '$ph_business', '$ph_mobile', '$email', '$occupation', '$interests', '$nominated_person')"; 
		$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); 

		echo 'Entry successful. <a href="confirmed.php">Click Here To Finish Signup</a>.'; 

		mysql_close($dbconn); 
	&#125; else &#123; 
		echo "The Following Errors Were Incountered:<br />"; 
		echo "<ul>"; 
		for ($x=0; $x<sizeof($errorlist); $x++) &#123; 
			echo '<li>'.$errorlist&#1111;$x]; 
		&#125; 
		echo "</ul>"; 
	&#125;
&#125; 
?>
The INSERT statement will have to be updated to get it's info from the $_POST array.

Mac