Not Adding 0 At Beginning Of Record

Hi Guys,

I have a little problem, when a new record is added its not adding the 0 at the beginning. For example lets say i have a form asking for their telephone number and the type the following in:

01234567890

They hit the submit button but only the following is added to the database.

1234567890

As you can see the 0 at the beginning is missing. I have the field in the database as Text and have also tried Number too. Any help as to why this is happening would be great please.

Thanks

can you post some code?


function quote_smart($value)  
{  
   // Stripslashes  
   if (get_magic_quotes_gpc()) {  
       $value = stripslashes($value);  
   }  
   // Quote if not a number or a numeric string  
   if (!is_numeric($value)) {  
       $value = "'" . mysql_real_escape_string($value) . "'";  
   }  
   return $value;  
} // end make safe


$firstname=$_POST["firstname"];
$telephone=$_POST["telephone"];
$email=$_POST["email"];
$ip=$_SERVER['REMOTE_ADDR'];
$lastname=$_POST['lastname'];
$affid=$_POST['affid'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Oops theres an error, our highly trained monkeys have been notified.");

$query = sprintf("INSERT INTO RedDrivingLessons VALUES ('',%s,%s,%s,%s,%s,%s,%s,%s,%s)",
			quote_smart($firstname),
			quote_smart($lastname),
			quote_smart($email),
			quote_smart($telephone),
			quote_smart($postcode),
			quote_smart($ip),
			quote_smart($datenow),
			quote_smart($timenow),
			quote_smart($affid));
//echo $query;
mysql_query($query) or dies(mysql_error());
mysql_close();

Do an echo of $query

My guess is the quote_smart function sees the telephone number as numeric, so you put that value without quotes in the query, and although the receiving column is of type text, it still looses the leading zero because it is treated as an integer by mysql before it is stored in the table.

Hi,

Thanks for your help so far!

INSERT INTO ***** VALUES (‘’,‘Mike’,‘Mikey’,‘mike@edd.com’,01923212390,‘’,‘81.178.xx.xx’,20111026,170030,‘’)

Thats the query. As you can see the 0 is still in there.

Thanks

Yes, like I said I think the leading zero is eliminated by MySQL because you didn’t put the value between quotes. If it’s a string, put quotes around it.

Sorry i miss-read what you wrote, thanks fixed :slight_smile:

Thank you!

if it’s a phone number, the column should be VARCHAR, not TEXT