New User Script Failing Unexpectedly.
| From: | Adam Bishop | Date: | Mon, 01 Sep 2003 18:14:05 +0000 |
| Subject: | New User Script Failing Unexpectedly. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-161373@lists.php.net to get a copy of this message | ||
Okay, this is a tricky one (i think so, anyway!), and rather long but pleeeeeeeease help me! I
don't expect you to spend hours looking at the problem, but any insight is appreciated.
I am (trying) to create a members only website. However, I am having a spot of bother. It all
works perfectly... The second time you fill in any form.
first, the user goes to newuser_process.php (Sample A) (the same thing happens if the user goes to
apply.php, I might add).
Then, the user fills in the form, and submits it to newuser_process.php
the program then checks for blank fields, which it finds none. it then goes on to check individual
fields, and here it hangs.
it executes the if block (even though the condition is not true), and re-shows the form, with the
error message, but with nothing in the fields.
If you fill in the form again, it works.
help!!!
So far, I have re-arranged the validation order, to see if that makes a difference, but it always
fails on the first if loop.
I have also tried to manually recreate the variables on sample 'B' (apply.php) (shown in
green, if you have html formatting enabled.
Other than that, I am totally clueless.
You can reach me at any of the adresses at the end of the e mail, for any solutions, queries about
my aims/ideals in this script, or anything else.
P.s. The .inc files and .js files are totally unrelated to the newuser script.
Thanks,
Adam Bishop
Sample 'A'
<?PHP
switch (@$do)
{
case "process":
session_start();
session_register('Sauth');
session_register('Slogname');
session_register('Spermissionlevel');
session_register('Sapprove');
include("thing.inc");
foreach($HTTP_POST_VARS as $key2 => $value2)
{
$$key2 = $value2;
}
foreach($HTTP_POST_VARS as $key => $value)
{
if ($key != "address2")
{
if ($key != "mobno")
{
if ($value == "")
{
unset($do);
$message_new = "You have missed a required field. Please check back and fill in the required
data";
include("apply.php");
exit();
}
}
}
$$key = strip_tags(trim($value));
}//end of foreach loop
if (!ereg("^[0-9]{11,11}$",$telno))
{
unset($do);
$message_new = "Your telephone number does not appear to be valid. Please try again.";
include("apply.php");
exit();
}
if ($mobno != "")
{
if (!ereg("^[0-9]{11,11}$",$mobno))
{
unset($do);
$message_new = "Your mobile number does not appear to be valid. Please try again.";
include("apply.php");
exit();
}
}
if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$email))
{
unset($do);
$message_new = "Your e mail address does not appear to be valid. Please try again.";
include("apply.php");
exit();
}
if ($password != $password2)
{
unset($do);
$message_new = "Your passwords do not match. Please try again.";
include("apply.php");
exit();
}
$connection = mysql_connect($host,$user,$password) or die("Couldn't Connect to
server");
$sql = "SELECT username FROM members WHERE username='$username'";
$result = mysql_query($sql) or die("Failed to check user name");
$num = mysql_numrows($result);
if ($num != 0)
{
unset($do);
$message_new = "Username already taken. Please choose another.";
include("apply.php");
exit();
}
else
{
/*Submits user to database.*/
}
default:
include("apply.php");
}
?>
sample 'B'
<?PHP
include("thing.inc");
foreach(HTTP_POST_VARS as $key3 => $value3)
{
$$key3 = $value3;
}
?>
<HTML>
<HEAD>
<!--The next section calls up the external files-->
<LINK REL=StyleSheet HREF="css/default.css" TYPE="text/css"
MEDIA="screen">
<SCRIPT SRC="js/functions.js" LANGUAGE="JAVASCRIPT">
</SCRIPT>
<TITLE>
Welcome to the Didcot Explorers Website
</TITLE>
</HEAD>
<BODY>
<!--This table contains only the title image-->
<TABLE BORDER="0" BGCOLOR="WHITE" CELLSPACING="15"
CELLPADDING="0" WIDTH="100%">
<TR>
<TD COLSPAN="2" BGCOLOR="WHITE">
<IMG SRC="images/title.jpg"></TD>
</TR>
</TABLE>
<!--This table contains everything else-->
<TABLE BORDER="0" BGCOLOR="WHITE" CELLSPACING="15"
CELLPADDING="3" WIDTH="100%">
<TR>
<!--This cell contains the word 'navigation'-->
<TD WIDTH="18%" CLASS="navigation">
<CENTER>
Navigation
</CENTER>
</TD>
<TD ROWSPAN="2" WIDTH="82%" CLASS="2" VALIGN="TOP">
<!--This is the main frame. Put the main body of the file here-->
<H2><B><I>Becoming A Member:</I></B></H2>
<P>
In order to become a member of the Didcot Explorer website, you must be an attending member. If you
still want to become a member, you must fill in all of this form.
<P>
<?PHP
if (isset($message_new))
{
echo "<FONT COLOR='RED'><B>$message_new</B></FONT>";
}
?>
<CENTER>
<FORM ACTION="newuser_process.php?do=process" METHOD="POST">
<TABLE BORDER="0" WIDTH="85%">
<TR><TD
COLSPAN="2"><B><I>Names:</B></I></TD></TR>
<TR><TD ALIGN="RIGHT">First Name: </TD><TD><INPUT
TYPE="TEXT" NAME="fname" VALUE="<?PHP echo @$fname
?>"></TD></TR>
<TR><TD ALIGN="RIGHT">Second Name: </TD><TD><INPUT
TYPE="TEXT" NAME="lname" VALUE="<?PHP echo @$lname
?>"></TD></TR>
<TR></TR>
<TR><TD
COLSPAN="2"><B><I>Address:</B></I></TD></TR>
<TR><TD ALIGN="RIGHT">1st Line of Address: </TD><TD><INPUT
TYPE="TEXT" NAME="address1" VALUE="<?PHP echo @$address1
?>"></TD></TR>
<TR><TD ALIGN="RIGHT">2nd Line of Address: <BR><FONT
SIZE="2">(optional)</TD><TD><INPUT TYPE="TEXT"
NAME="address2" VALUE="<?PHP echo @$address2 ?>"></TD></TR>
<TR><TD ALIGN="RIGHT">Town: </TD><TD><INPUT
TYPE="TEXT" NAME="town" VALUE="<?PHP echo @$town
?>"></TD></TR>
<TR><TD ALIGN="RIGHT">County: </TD><TD><INPUT
TYPE="TEXT" NAME="county" VALUE="<?PHP echo @$county
?>"></TD></TR>
<TR><TD ALIGN="RIGHT">Postcode: </TD><TD><INPUT
TYPE="TEXT" NAME="postcode" VALUE="<?PHP echo @$postcode
?>"></TD></TR>
<TR></TR>
<TR><TD COLSPAN="2"><B><I>Contact
Numbers:</B></I></TD></TR>
<TR><TD ALIGN="RIGHT">Telephone Number: <BR><FONT
SIZE="2">(inc. Area code)</TD><TD><INPUT TYPE="TEXT"
NAME="telno" VALUE="<?PHP echo @$telno ?>"></TD></TR>
<TR><TD ALIGN="RIGHT">Mobile Number: <BR><FONT
SIZE="2">(optional)</TD><TD><INPUT TYPE="TEXT"
NAME="mobno" VALUE="<?PHP echo @$mobno ?>"></TD></TR>
<INPUT TYPE="HIDDEN" NAME="permission" VALUE="1">
<INPUT TYPE="HIDDEN" NAME="approve" VALUE="No">
<TR></TR>
<TR><TD COLSPAN="2"><B><I>User
Details:</B></I></TD></TR>
<TR><TD ALIGN="RIGHT">E-mail address: </TD><TD><INPUT
TYPE="TEXT" NAME="email" VALUE="<?PHP echo @$email
?>"></TD></TR>
<TR><TD COLSPAN="2"><B><I>Please Select the
Following:</B></I></TD></TR>
<TR><TD ALIGN="RIGHT">Username: </TD><TD><INPUT
TYPE="TEXT" NAME="username" VALUE="<?PHP echo @$username
?>"></TD></TR>
<TR><TD ALIGN="RIGHT">Password: </TD><TD><INPUT
TYPE="PASSWORD" NAME="password" VALUE="<?PHP echo @$password
?>"></TD></TR>
<TR><TD ALIGN="RIGHT">Confirm Password: </TD><TD><INPUT
TYPE="PASSWORD" NAME="password2" VALUE="<?PHP echo @$password2
?>"></TD></TR>
<TR><TD COLSPAN="2"><CENTER><INPUT TYPE="Submit"
VALUE="Apply For Membership">
<INPUT TYPE="Reset" VALUE="Reset
Form"></CENTER></TD></TR>
</FORM>
</TABLE>
</CENTER>
</TD>
<TR>
<?PHP
include("inc/navigation.inc");
?>
</TR>
</TABLE>
</BODY>
</HTML>
TMX@ntlworld.com
Themysteriousx@ntlworld.com
Themysteriousx@hotmail.com
Adambishop50@hotmail.com
Themysterious_x@yahoo.com
Adambishop50@lycos.co.uk
_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger