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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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