Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: if statement

  1. #1
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts

    if statement

    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


    PHP Code:



    if($fname && $lname 4){

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

    }


    if(
    $password && $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 { 

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the wrong forum,if the moderator would be so kind to move it.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    might as well answer it anyway.

    what you want is to call in the function:

    strlen(n)

    eg.

    PHP Code:
    $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
    Last edited by duniyadnd; 11-26-2002 at 02:47 PM.

  • #4
    New Coder
    Join Date
    Nov 2002
    Location
    Netherlands
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It was already crossposted in the php forum and answered there.

  • #5
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)
    PHP Code:
    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).
    PHP Code:
     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
    PHP Code:

    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>"); 

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Depends on the time of year
    Posts
    478
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    <?
    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));

      }

     }
    ?>

  • #7
    Banned
    Join Date
    Aug 2002
    Posts
    111
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did your way,but I got an error.

    Please tell me what it is wrong.

    Thank you for your time.

    BYe for now



    PHP Code:


    <?
    function testing() 
     {

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

    if (
    strlen($password)<|| $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 {


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •