Jump to content

Phone Numbers - PHP is subtracting them.


aesthetics1

Recommended Posts

Hello,

 

This is probably something quick and simple.

 

I have a web form that is entering information into a database, specifically a phone number in 555-555-5555 format. My SQL Query looks like this:

 

$sql = "INSERT INTO $database.`service` (`customer_no`, `serial`, `phone`) VALUES ($customer_no, $serial, $phone)";

 

which outputs values like this:

 

VALUES (number, number, 555-555-5555)

 

my problem is, when the phone number is entered into the database, it isn't putting "555-555-5555" it's putting in -5555 (The difference of 555 minus 555 minus 5555...)

 

How can I stop this from happening in this instance?

Link to comment
https://forums.phpfreaks.com/topic/205455-phone-numbers-php-is-subtracting-them/
Share on other sites

Phone numbers, despite being called numbers are actually formatted strings of numeric digits and separator characters. I also hope your field type in your table is not numeric because only the first three characters before the first - will be stored in a numeric field.

 

You need to surround your phone numbers in single-quotes so that they will be treated as a string instead of a mathematical expression.

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.