Jump to content

I got mobile number to validate but I am stuck at the prefix part.


rahul19dj

Recommended Posts

if(empty($_POST['mobileno'])) // phone number is not empty
{
$error[] = 'Please enter mobile number';
} else {
if(preg_match('/^\d{10}$/',$_POST['mobileno'])) // phone number is valid
{
  $mobile = $_POST['mobileno'];
  // your other code here
}
else // phone number is not valid
{
  $error[] = 'Phone number invalid !';
}
}
$prefix = 0;
$pmobile = $prefix . $mobile;

This is what I am trying to do for prefix. Is this right as I cant add the value 0 before the number.

 

This is my insert statement

 

 $query_verify_mobileno = "SELECT * FROM userdtls WHERE mobileno = '$pmobile'";
        $result_verify_mobileno = mysqli_query($dbc, $query_verify_mobileno);
        if (!$result_verify_mobileno) 
	{//if the Query Failed ,similar to if($result_verify_mobileno==false)
            echo ' Database Error Occured ';
        }

        if (mysqli_num_rows($result_verify_mobileno) == 0) 
	{ // IF no previous user is using this number .


            // Create a unique  activation code:
           //$activation = md5(uniqid(rand(), true));


            $query_insert_user = "INSERT INTO userdtls ( mobileno, serviceprovider, pass, fname, lname, email, citystate, MUM, PUN, BNG, MYS ) VALUES ( '".$pmobile."', '".$serviceprovider."', '".$password."', '".$fname."', '".$lname."', '".$email."', '".$citystate."','".$mumbai."', '".$pune."', '".$banglore."', '".$mysore."'  )";
            

i'm not the brightest around here will database intricaces, but i do believe if you set the attributes to 'unsigned zerofill' you should be okay. 

 

PS, if that other thread is done, mark it solved ploxxors

 

PPS: are the phone numbers you're storing always 10 digits?

zerofill will maintain the integer count you specified ( which, btw, you don't need bigint )and produce leading zeros. say you store 567, zerofill should give 0567 on a int(4). maybe it's the other way around, i dunno for sure.  but if you're going to store the numbers formatted, which it would make sense to, you should just save it as a string.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.