Search code examples
phphtmlmysqlformsmysql-real-escape-string

How to mysql_real_escape_string a zero


I'm trying to input a phone number from a html form to my MySQL database with mysql_real_escape_string. The number is 0123456789, but it's written as 23456789 in my database. Does anyone know how to insert that zero along with the other numbers in my database, or if there is any way to break the form value in to characters then input them one by one into my MySQL db?

Here's my code that doesn't input the zero:

<?php
$Phone = mysql_real_escape_string($_POST['phone']);
mysql_query("INSERT INTO `user` (`phone`) VALUES ('{$Phone}')");
?>

Solution

  • That has nothing to do with escaping. You need to store the value as a string, not an integer, if you want to maintain leading zeros.