Forum Moderators: coopster

Message Too Old, No Replies

scrambled phone numbers

php pulls info from mysql db . . but mixes up the phone numbers

         

driven_snow

1:59 pm on Mar 16, 2004 (gmt 0)

10+ Year Member



Hey!

I'm using php to display information ( name and phone numbers ) from a mysql database, and it's all just peachy keen, but the phone numbers are scrambled if the area code is included.

( That is to say, if there are more than seven numbers in the number. )

This is the php :

<?php
if ($submit) {
// process form
$db = mysql_connect("******", "*****", "*****");
mysql_select_db("spookypurpledragon",$db);
$sql = "INSERT INTO call (name,phone_number) VALUES ('$name','$phone_number')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
} else{
// display form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
Name:<input type="Text" name="name"><br>
Phone_number:<input type="Text" name="phone_number"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
} // end if
?>

And just in case, here is how I created the database :

mysql -> create table call
> name VARCHAR (15),
> phone_number INT,
> ID INT NOT NULL AUTO_INCREMENT,
> primary key (id));

And if the phone number was, say, 14445556666, it displays as 48394729876. :?

Does anybody know why the phone numbers get scrambled?

Gorilla

2:09 pm on Mar 16, 2004 (gmt 0)

10+ Year Member



Quick answer: Never store phone numbers as integers, use text. You'll loose leading zeros when you use interger type for phone numbers.

DoppyNL

2:13 pm on Mar 16, 2004 (gmt 0)

10+ Year Member



also, when you store the phone numbers as an int and someone enters a phone number like this:

123-456-7890 ( - for splitting it up)

the database might decide it has to calculate the result and then store that...
best is to use strings.

driven_snow

2:44 pm on Mar 16, 2004 (gmt 0)

10+ Year Member



Thanks y'all. :D

Works like a charm now. ( I changed the number from integer to varchar ).