PDA

View Full Version : if statment


0810
11-26-2002, 06:04 AM
Hi how are you? My script doesn't work because even though I put fname and lname less than 4, it goes to my database.

What I like to do is fname and lname have to be more than 4 characters and password alos has to me more thatn 4 characters. Password and confirme should be same.

I did like this but not working

could you help me out

Thanks





if($fname < 4 && $lname < 4){

print("You firstname and lastname should be more than 4 characters.<br>\n");

}


if($password < 4 && $password!=$confirm ){

print("Password and Confirm are not right,<br>go back to sign up again<br>\n");
print("<a href=\"sign.php\">Here sign up again please!</a>");

}




if($password==$confirm){




$query_insert = "insert into kk (fname,lname,mail,username,password ,confirm) values ('$fname','$lname','$mail','$username', '$password', '$confirm')";
$query_result_insert = mysql_query($query_insert, $con) or die (mysql_error($con));







print("<html><body background=\"image/kareha.gif\">");
print "Thank you for filling out my form.<br> <a href=\"Ja1test.php\">Click here</a> to go back to the homepage.<br>\n";
print("Now it is fall and soon coming winter<br>Time goes fast. ");
print("<center><img src=\"image/falltrees.gif\"></center>");
print("</body></html>");
mysql_close($con);
}
} else {

Dylan Leblanc
11-26-2002, 07:04 AM
I think the first line should be:


if(strlen($fname) < 4 && strlen($lname) < 4){

Ankun
11-26-2002, 06:32 PM
dont you have to use less than equal to? like <= because I think php is weird or something, i've seen alot of people have to put <= when all that was really needed is < :\ so if '<' dun work then try '<='

raptori
11-26-2002, 09:02 PM
Originally posted by Dylan Leblanc
I think the first line should be:


if(strlen($fname) < 4 && strlen($lname) < 4){
also this line
if($password < 4 && $password!=$confirm ){

0810
11-27-2002, 02:25 AM
Hi how are you doing?

I fixed like this


I tested many times this scirpt but whole messages come when I click submit button.

even though it is wrong, it goes my database.

what I want to do is that if fname and lanme don't have more than 4 characters ,it comes only this message.(not go to my database)


print("You firstname and lastname should be more than 4 characters.<br>\n");


if password has no more than 4 characters and password is not equal to confirm, it comes only this message.(not go to my database).


print("Password and Confirm are not right,<br>go back to sign up again<br>\n");
print("your password should be more than 4 characters.<br>\n");
print("<a href=\"sign.php\">Here sign up again please!</a>");



if it is true everything, it goes that datas to my database, then it comes only this message


print("<html><body background=\"image/kareha.gif\">");
print "Thank you for filling out my form.<br> <a href=\"Ja1test.php\">Click here</a> to go back to the homepage.<br>\n";
print("Now it is fall and soon coming winter<br>Time goes fast. ");
print("<center><img src=\"image/falltrees.gif\"></center>");
print("</body></html>");

druffus
11-27-2002, 07:26 AM
Hi 0810,

If your code is exactly what you have i would see two problems. One the strlen() problem which has been mentioned. And two, if you take a close look, you check for the first two things, but if they are wrong it still checks the confirm password and puts it in the DB. To illistrate...



if((strlen($fname) < 4) && (strlen($lname) < 4)){
print("You firstname and lastname should be more than 4 characters.<br>\n");
}

//You checked the length and now we go onto the next if statement either way

if((strlen($password) < 4) && ($password!=$confirm)){
print("Password and Confirm are not right,<br>go back to sign up again<br>\n");
print("<a href=\"sign.php\">Here sign up again please!</a>");
}

//You checked the length/confirmation and now we go onto the next if statement either way
//Therefore in this situation, even if you have the wrong lengths, as long as you have matching passwords it will work.

if($password==$confirm){

$query_insert = "insert into kk (fname,lname,mail,username,password ,confirm) values ('$fname','$lname','$mail','$username', '$password', '$confirm')";
$query_result_insert = mysql_query($query_insert, $con) or die (mysql_error($con));


print("<html><body background=\"image/kareha.gif\">");
print "Thank you for filling out my form.<br> <a href=\"Ja1test.php\">Click here</a> to go back to the homepage.<br>\n";
print("Now it is fall and soon coming winter<br>Time goes fast. ");
print("<center><img src=\"image/falltrees.gif\"></center>");
print("</body></html>");
mysql_close($con);
}
} else {




Here is a try at a possible solution




if((strlen($fname) < 4) && (strlen($lname) < 4)){

//Code for wrong name lengths

} else if((strlen($password) < 4) && ($password!=$confirm)){

//Code for wrong password or no confirmation of password

} else {

//Code to enter into DB

$query_insert = "insert into kk (fname,lname,mail,username,password ,confirm) values ('$fname','$lname','$mail','$username', '$password', '$confirm')";
$query_result_insert = mysql_query($query_insert, $con) or die (mysql_error($con));

}



See the difference? I check in the first one for the right name lengths, if they are ok, then i check for the next one, if they are ok, then we can put into the database.

Hope that is one the right track. Good Luck.

duniyadnd
11-27-2002, 10:54 AM
you posted the same question on another section of the discussion board (Html and CSS), and to answer your updated questions, the above answer should solve it. If there's still any further problems, let us know.

Duniyadnd