Lamez Posted June 29, 2008 Share Posted June 29, 2008 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"); } } Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/ Share on other sites More sharing options...
thatsgreat2345 Posted June 29, 2008 Share Posted June 29, 2008 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) Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577466 Share on other sites More sharing options...
Psycho Posted June 29, 2008 Share Posted June 29, 2008 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'])) Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577471 Share on other sites More sharing options...
kenrbnsn Posted June 30, 2008 Share Posted June 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577791 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 yes that is post data ($subphone) it is defined earlier. I could put this phone number 8065798990 in the field and it returns as it was too small, under 10 digits. Is there a way to fix that? Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577800 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 <?php if($subphone <10){ //should check to see if it is less than 10 }else if($subphone >10){ // checks to see if it is greater than 10 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577815 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 oh man I found out what was wrong, is there a way to check to see if it is numbers only? Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577832 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 if(is_numeric($string) { } Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577835 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 thanks that helped, well now I looked in the database and it is not storing the phone numbers right. Example: 8775778990 Outcome: 2147483647 why? Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577842 Share on other sites More sharing options...
interpim Posted June 30, 2008 Share Posted June 30, 2008 We would need to see how you are storing the numbers first... what are the fields in your database etc... Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577843 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 --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 Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577845 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 in your database what is the field type? INT or varchar? i suggest you put it to int Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577846 Share on other sites More sharing options...
interpim Posted June 30, 2008 Share Posted June 30, 2008 And I assume you are retrieving the phone number based off of the username field? It looks good to me... can I see your query to pull up the phone number? Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577847 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 it is in there as a int I have no query to pull it out just yet, I am looking at it using Phpmyadmin Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577848 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 $phone = trim(mysql_real_escape_string(strip_tags($_POST['phone']))); Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577850 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 nope, nothing Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577854 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 int() ?? whats the value for the Int field? also is it set to 'unsigned' so you dont get negative numbers (invalid phone number). You could store the phone number as a string. varchar(50); Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577856 Share on other sites More sharing options...
darkfreaks Posted June 30, 2008 Share Posted June 30, 2008 int as in the database type Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577857 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 int(10) is what it is as in the database Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577858 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 let me try varchar. Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577859 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 int as in the database type whats with all the sarcasm today lol Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577860 Share on other sites More sharing options...
Lamez Posted June 30, 2008 Author Share Posted June 30, 2008 wow that did it, it is in there as I signed up with. Thanks for all the help guys Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577862 Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 no problem, have a nice day Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/112466-solved-my-phone-number-check-cant-read-0/#findComment-577866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.