473,382 Members | 1,225 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Validation & Error Checking Broken??

Hi, I'm validating a simple form for input via post ($PHP_SELF). Near the
end I check for username and password. I'm using simple if, elseif, else
statements.

I require them to enter password twice and check that they match. Problem is
script doesn't valide past username input and I dont know why!! If you don't
enter a password it doesn't do the validation anymore, it just dies for some
reason. I would greatly appreciate anyones help, I've stared at this thing
for hours and hours.

Here is code...
while(list($key, $value) = each($HTTP_GET_VARS)) {

echo "$key = $value<br>";

}
if ($form && strpos($HTTP_REFERER, $SCRIPT_NAME) > 0) {
$cfirstname = clean($cfirstname);
$clastname = clean($clastname);
$lname = clean($lname);
$laddress1 = clean($laddress1);
$laddress2 = clean($laddress2);
$lcity = clean($lcity);
$lstate = clean($lstate);
$lzip = clean($lzip);
$lcountry = clean($lcountry);
$lareacode = clean($lareacode);
$lprefix = clean($lprefix);
$lsuffix = clean($lsuffix);
$lintcode = clean($lintcode);
$ldayrate1 = clean($ldayrate1);
$ldayrate2 = clean($ldayrate2);
$ldescription = clean($ldescription);
$remail = lower(clean($remail));
$username = lower(clean($username));
$password = lower(clean($password));
$password2 = lower(clean($password2));

if ($username) {

$q = "SELECT id FROM account WHERE username='". apos($username) ."'";
$res = mysql_query($q);
$num = mysql_num_rows($res);

if ($num > 0) {
$focus = "username";
$msg = "This username is taken, please choose a different one.";

}} elseif ($password != $password2) {
$focus = "password2";
$msg = "Passwords do not match.";

} elseif (!$cfirstname) {
$focus = "cfirstname";
$msg = "Please enter your first name.";

} elseif (!$clastname) {
$focus = "clastname";
$msg = "Please enter your last name.";

} elseif (!$lname) {
$focus = "lname";
$msg = "Please enter the name of your lodging.";

} elseif (!$laddress1) {
$focus = "laddress1";
$msg = "Please enter your lodging's physical address.";

} elseif (!$lcity) {
$focus = "lcity";
$msg = "Please enter your city.";

} elseif (!$lstate) {
$focus = "lstate";
$msg = "Please select/enter your state or province.";

} elseif (!$lzip) {
$focus = "lzip";
$msg = "Please enter your postal code.";

} elseif (!$lcountry) {
$focus = "lcountry";
$msg = "Please enter your country.";

} elseif (!$rphone) {
$focus = "rphone";
$msg = "Please enter your reservations phone number";

} elseif (!$ldayrate1) {
$focus = "ldayrate1";
$msg = "Please enter your minimum daily rate.";

} elseif (!$ldayrate2) {
$focus = "ldayrate2";
$msg = "Please enter your maximum daily rate.";

} elseif (!$ldescription) {
$focus = "ldescription";
$msg = "Please provide a description of your lodging.";

} elseif (strlen($ldescription) > 200) {
$focus = "ldescription";
$msg = "Your description is limited to 200 characters.";

} elseif (!is_valid_email($remail)) {
$focus = "remail";
$msg = "Please enter a valid email address.";

} elseif (!$username) {
$focus = "username";
$msg = "Please enter a username.";

} elseif (!$password) {
$focus = "password";
$msg = "Please enter a password.";

} elseif (!$password2) {
$focus = "password2";
$msg = "Please re-enter your password.";

} else { etc, etc..
Jul 17 '05 #1
2 2623
Philip D Heady <pd*****@comcast.net> wrote:
Hi, I'm validating a simple form for input via post ($PHP_SELF). Near the
end I check for username and password. I'm using simple if, elseif, else
statements.

I require them to enter password twice and check that they match. Problem is
script doesn't valide past username input and I dont know why!! If you don't
enter a password it doesn't do the validation anymore, it just dies for some
reason. I would greatly appreciate anyones help, I've stared at this thing
for hours and hours.
...
if ($username) {

$q = "SELECT id FROM account WHERE username='". apos($username) ."'";
$res = mysql_query($q);
$num = mysql_num_rows($res);
if ($num > 0) {
$focus = "username";
$msg = "This username is taken, please choose a different one.";

}} elseif ($password != $password2) {

^^^^^^^^^^^^^^^^^^^^^^^
this is your problem, i think. probably you are testing unset variables
with the != test.
how about first testing for emptiness, and then checking whether your
passwords match? something like:

if (!$username || empty($username)) {
$focus = "username";
$msg = "Please enter a username.";
} elseif (!$password || empty($password)) {
$focus = "password";
$msg = "Please enter a password.";
} elseif (!$password2 || empty($password2)) {
$focus = "password2";
$msg = "Please re-enter your password.";
} elseif ($password != $password2) {
$focus = "password2";
$msg = "Passwords do not match.";
} elseif (
...
...
} else {
$q = "SELECT id FROM account WHERE username='". apos($username) ."'";
$res = mysql_query($q);
$num = mysql_num_rows($res);
if ($num > 0) {
$focus = "username";
$msg = "This username is taken, please choose a different one.";
}
}

regards,
steven.
Jul 17 '05 #2
Yep, moving the username error checking to the bottom fixed problem. I also
made use of empty() function. Thanks.

Philip D. Heady
http://www.ignission.com
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: AnnMarie | last post by:
<script language="JavaScript" type="text/javascript"> <!-- function validate(theForm) { var validity = true; // assume valid if(frmComments.name.value=='' && validity == true) { alert('Your...
16
by: J. C. Denton | last post by:
I just manually validated alexa's global top 100 sites and find only 2 sites that pass validation. They are http://www.microsoft.com/ http://www.wikipedia.org/ All others should go w3c...
1
by: iMedia User | last post by:
I have a site where I want to use the Web form validators in two separate forms on a single page. One form allows existing users to log in while the second one allows new users to register. The...
12
by: Nalaka | last post by:
Hi, I suddenly started getting a lot of errors from html validation (some CSS) so I followed the following instructions to disable it. If you'd rather not have these types of HTML validation...
2
by: this one | last post by:
I have the following code <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript"...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
0
by: Mudiya Dissa | last post by:
Hi, I have some code on my application like the following <% redirectUrl = "mypage.asp?type=100&id=something&view=10 'some more asp code
2
by: william.oram | last post by:
I have a few controls on a basic form I'm working on that make use of postback: for example, click a checkbox to make Panel1 and its subcontrols visible. I've since added clientside and...
2
by: akhilesh.noida | last post by:
I am trying to compile glibc-2.5 for ARM based board. But I am getting errors while configuring it. Please check and give your inputs for resolving this. configure command : $...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.