Development help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Development help

    Ok so whenever I code something I tend to do things the looong way.I was hoping someone here could help me shorten thing out. For example I would type:
    if(empty($username)) {
    die("please enter a username");
    }
    And I would repeat this several times just to make sure that the form was filled in. What is the correct way to do this? This is just one of the examples. Thanks for your help
    Visit my site

    #2
    do it like this
    PHP Code:
    if($username=="") {
    echo 
    "please enter a username";
    exit();

    that way the rest of your script will stop executing or u can just add the exit function to the script u posted
    Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

    Comment


      #3
      Thanks Kev but how can I check username, password etc all at once.
      Visit my site

      Comment


        #4
        if(empty($username)||empty($pass)||empty($sex)) {
        die("wtf");
        }
        <?php unlink('World/Europe/Romania.country'); ?>

        Comment


          #5
          or try this


          if (check_blank($username)) { die(); // the field was left blank. }

          Comment


            #6
            you can use what i0nutzxp posted to check all at once
            Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

            Comment


              #7
              Ok thanks very much for the help guys. ;)
              Oh and btw if any one does decide to use:
              PHP Code:
              if($username=="") {
              echo 
              "please enter a username";
              exit();

              Make sure you use the ltrim and rtrim or else users can create a blank username with whitespace.
              Visit my site

              Comment


                #8
                Whats wrong with this?
                PHP Code:
                if (strlen($username 10)) {
                die (
                "Username to big");

                If I make the length of the username bigger than 10 it does not show an error. Can someone please help me.
                Visit my site

                Comment


                  #9
                  try like this


                  PHP Code:
                  $username mysql_real_escape_string($_POST['username']);

                  if(
                  strlen($username) > 10)){
                          echo 
                  "username is too long!";
                  }
                   
                  $db->query('SELECT * FROM users WHERE username="'.$username.'"');
                  if(
                  $db->num_rows()){
                          echo 
                  "username is already in use";
                  }


                  also  you  can  use  this   one 
                  if(strlen($username)<3){
                          echo 
                  "username is too short!";

                  Last edited by GiLL; 25.03.10, 13:36.
                  left wap stuff

                  Comment


                    #10
                    You are doing something wrong it should be like this
                    PHP Code:
                    if( strlen($username) < 10 ) { die ("Username to big"); } 
                    Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

                    Comment


                      #11
                      Yes thanks guys its working now.
                      Visit my site

                      Comment

                      Working...
                      X