Adrian P.
Adrian P.

Reputation: 5228

PHP / MySQL varchar field entered as a number

I have within a form a textbox named PO_Number. The form submit by post to another page the textbox value.

In the second page I get $_POST['PO_Number'] and enter in MySQL.

MySQL field is varchar(15). As soon as the string of PO_Number starts with a letter or a number everything is OK.

The problem: sometimes the PO (Purchase Order) number start with 00 or 000 and it is stored with a comma before the 00
For example:
GH93737 - works
9087893 - works
0011132 - entered in database as ,0011132 (see the comma?)

The insert looks normal:

mysql_query("INSERT INTO table_name (PO_Number, ....) VALUES ('".$_POST['PO_Number']."',......)");

Many thanks for your suggestions and your help.

Upvotes: 0

Views: 637

Answers (1)

gtr1971
gtr1971

Reputation: 2732

I'm wondering if this has something to do with your browser/server character encoding and how it's interpreting those specific numbers because all of those leading zeros and ones might be getting interpreted as a binary number?

Here's some brief info on that point:

A character encoding tells the computer how to interpret raw zeroes and ones into real characters. It usually does this by pairing numbers with characters.

http://htmlpurifier.org/docs/enduser-utf8.html

Upvotes: 1

Related Questions