...

View Full Version : if statement



0810
11-26-2002, 05:47 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 {

Bosko
11-26-2002, 02:11 PM
This is the wrong forum,if the moderator would be so kind to move it.

duniyadnd
11-26-2002, 02:45 PM
might as well answer it anyway.

what you want is to call in the function:

strlen(n)

eg.



$stringlength = strlen($fname);

if ($stringlength < 4)
{
echo "nope";
}



what you were doing prior to this was getting the value of the string, not the length. strlen(n) looks for the number of characters in the string itself.

Duniyadnd

Wichetael
11-26-2002, 03:40 PM
It was already crossposted in the php forum and answered there.

0810
11-26-2002, 06:37 PM
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>");

duniyadnd
11-26-2002, 07:22 PM
okay, now you got the lengths of the entries. Now if you want to restrict what goes into the tables, it comes to a javascript solution, or you can try these around:



<?
function testing()
{

if (condition 1)
{
blah blah blah
itsFalse();
}

if (condition 2)
{
blah blah blah
itsFalse();
}

if (condition 1)
{
blah blah blah
itsTrue();
}

function itsFalse()
{
?> <script language="javascript" type="text/js">
<!--
window.location="http://www.someotherlink.html"
-->
</script>
<?
}

function itsTrue()
{
$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));

}

}
?>

0810
11-26-2002, 09:22 PM
I did your way,but I got an error.

Please tell me what it is wrong.

Thank you for your time.

BYe for now







<?
function testing()
{

if (strlen($fname)<4 || stren($lname)<4)
{
print("More than 4 characters<br>\n");
itsFalse();
}

if (strlen($password)<4 || $password!=$confirm)
{
print("Not right Do it again<br>\n");
itsFalse();
}

if ($password==$confirm && $password>=4)
{
print("Thanks<br>\n");
itsTrue();
}

function itsFalse()
{
?> <script language="javascript" type="text/js">
<!--
window.location="thanks.html";
-->
</script>
<?
}





function itsTrue()
{




$query_insert = "insert into kk (fname,lname,mail,username, country, job, gender, password ,confirm) values ('$fname','$lname','$mail','$username','$country','$job','$gender', '$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 {



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum