aesthetics1 Posted June 21, 2010 Share Posted June 21, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/205455-phone-numbers-php-is-subtracting-them/ Share on other sites More sharing options...
kratsg Posted June 21, 2010 Share Posted June 21, 2010 Put single quotes around $phone: $sql = "INSERT INTO $database.`service` (`customer_no`, `serial`, `phone`) VALUES ($customer_no, $serial, '$phone')"; Quote Link to comment https://forums.phpfreaks.com/topic/205455-phone-numbers-php-is-subtracting-them/#findComment-1075157 Share on other sites More sharing options...
PFMaBiSmAd Posted June 21, 2010 Share Posted June 21, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/205455-phone-numbers-php-is-subtracting-them/#findComment-1075158 Share on other sites More sharing options...
aesthetics1 Posted June 21, 2010 Author Share Posted June 21, 2010 Thanks, the single quotes worked. I thought I tried that, but I got a parse error, must have fat-fingered it the first time. Thanks a lot. Yes, the database isn't a numeric only field. Thanks for that tidbit. Quote Link to comment https://forums.phpfreaks.com/topic/205455-phone-numbers-php-is-subtracting-them/#findComment-1075179 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.