form validation - Multiple IF conditions....
Posted: Sun Dec 28, 2003 11:48 am
with permission of the original poster moved from pm to this forum.
Hello:
I am VERY new to PHP and slowly learning. Here is a sample of my code:
[slightly reformatted]Code: Select all
<?php If ($btnSUB) { If (isset($fname) && $fname == "") { echo '<TR>'; echo '<TD CLASS=alerts1 COLSPAN="2">'; alertfunc(); echo '</TD>'; echo '</TR>'; } If (isset($lname) && $lname == "") { echo '<TR>'; echo '<TD CLASS=alerts1 COLSPAN="2">'; alertfunc2(); echo '</TD>'; echo '</TR>'; } If (isset($email) && $email == "") { echo '<TR>'; echo '<TD CLASS=alerts1 COLSPAN="2">'; alertfunc3(); echo '</TD>'; echo '</TR>'; } If ($passwd1 != $passwd2) { echo '<TR>'; echo '<TD CLASS=alerts1 COLSPAN="2">'; alertfuncconfirm(); echo '</TD>'; echo '</TR>'; } } Else { $upperfname = $fname; $upperfname = ucfirst($upperfname); $upperlname = $lname; $upperlname = ucfirst($upperlname); INCLUDE "dbconnect.php"; $sql = "INSERT INTO useraccount (FirstName,LastName,EmailAddress,Password,Timestamp,UserID) VALUES ('$upperfname','$upperlname','$email','$passwd1','$tstamp','$uid')"; $result = mysql_query($sql); echo "<SCRIPT>window.location="index.php";</SCRIPT>"; } ?>
Basically what I am "trying" to do is, I have a form with FIRST NAME, LAST NAME, EMAIL, and PASSWORD. I want to be able to say "if firstname is null then alert "sorry... you must enter a first name". Now, if firstname AND lastname is null, I want to be able to show two separate alerts at the same time like:
* Please enter your first name
* Please enter your last name
So.... for each field that is null.... I want to display a message. I am having issues with my nested IF statements..... HELP!
Thank you,
nonborn0