Jump to content

[SOLVED] My Phone Number Check Can't Read 0


Lamez

Recommended Posts

My phone validation cannot read 0's

 

here is my code :

 

	  	  	  
		  	        $field = "phone";  
      if(empty($_POST['phone'])){
         $form->setError($field, "* Phone Number not entered");
      }
		  
         else{
        $subphone = stripslashes($subphone);
         if(strlen($subphone) < 10){
            $form->setError($field, "* Phone Number too short");
 }
  }
  

Link to comment
Share on other sites

Right from PHP site for empty

The following things are considered to be empty:

    * "" (an empty string)
    * 0 (0 as an integer)
    * "0" (0 as a string)
    * NULL
    * FALSE
    * array() (an empty array)
    * var $var; (a variable declared, but without a value in a class)

Link to comment
Share on other sites

Where is $subphone first set? The first time I see it used you are trying to set it based upon it's already set value (which would be nothing?):

$subphone = stripslashes($subphone);

 

Is that supposed to be this:

$subphone = stripslashes($_POST['phone']);

 

Can you give an example of a value that your code does not work with? If you are stating that a single zero is generating the error for not entered, then the problem is as thatsgreat2345 suggests. In that case you would want to use isset():

if(!isset($_POST['phone']))

Link to comment
Share on other sites

Right from PHP site for empty

The following things are considered to be empty:

    * "" (an empty string)
    * 0 (0 as an integer)
    * "0" (0 as a string)
    * NULL
    * FALSE
    * array() (an empty array)
    * var $var; (a variable declared, but without a value in a class)

That's why I never use "if (empty($_POST['somefield']))" to check for blank input fields.

 

Do this instead:

<?php
     if(strlen(trim(stripslashes($_POST['phone']))) == 0){
?>

 

That checks to see if the length of the field's value is zero. If it is, then the field was blank.

 

Ken

Link to comment
Share on other sites

--DB--

username

password

userid

userlevel

email

first

last

phone

paid

setup

rules

about

age

avatar

aim

yahoo

icq

msn

xfire

ban

timestamp

------

 

Here is the script that adds them:

 

<?php
/* Errors exist, have user correct them */
      if($form->num_errors > 0){
         return 1;  //Errors with form
      }
      /* No errors, add the new account to the */
      else{
         if($database->addNewUser($subuser, md5($subpass), $subemail, $_POST['first'], $_POST['last'], $_POST['phone'])){
            if(EMAIL_WELCOME){
               $mailer->sendWelcome($subuser,$subemail,$subpass);
            }
            return 0;  //New user added succesfully
         }else{
            return 2;  //Registration attempt failed
         }
      }
   }
?>

 

here is the addNewUser function:

<?php
   /**
    * addNewUser - Inserts the given (username, password, email)
    * info into the database. Appropriate user level is set.
    * Returns true on success, false otherwise.
    */
   function addNewUser($username, $password, $email){
      $time = time();
      /* If admin sign up, give admin user level */
      if(strcasecmp($username, ADMIN_NAME) == 0){
         $ulevel = ADMIN_LEVEL;
      }else{
         $ulevel = USER_LEVEL;
      }
  $first = $_POST['first'];
  $last = $_POST['last'];
  $phone = $_POST['phone'];
  $paid = '0';
  $setup = '0';
  $rules = '0';
  $ban = '0';
  $avatar = 'user/usrava/default.jpg';
      $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', '$first', '$last', '$phone', '$paid', '$setup', '$rules', '$about', '$age', '$avatar', '$aim', '$yahoo', '$icq', '$msn', '$xfire', $ban, $time)";
  
  $total = "0";
  $rnd1 = "0";
  $rnd2 = "0";
  $rnd3 = "0";
  $rnd4 = "0";
  $rnd5 = "0";
  $champ = "0";
        $qu = "INSERT INTO `userpoints` VALUES ('$username', '$total', '$rnd1', '$rnd2', '$rnd3', '$rnd4', '$rnd5', '$champ')";
  
  include ("mailadmin.php");
  	  mysql_query($qu, $this->connection);
  return mysql_query($q, $this->connection);
   }
?>

 

hope that helps you to help me

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.