Muhammad
Muhammad

Reputation: 307

can we store negative (-) and plus (+) sign numbers in mysql varchar column

I need to store numbers with plus or minus signs in a varchar column in mysql. I am using php.

+100 saves 100

100+ the insert fails

-100 its ok shows -100

100- the insert fails

Upvotes: 2

Views: 4659

Answers (1)

user3522003
user3522003

Reputation:

According to the cases you specified, most probably you have not added the quotes to the values and MySQL treats the values as integers and then converts them to VARCHAR (in your first and third cases). Please check your INSERT-statement and add the quotes to value:

$query = "INSERT INTO table (field) VALUES ('$value')";

And of course it is better to use numeric datatypes for storing such values.

Upvotes: 1

Related Questions