PHP mysqli prepared statements removing leading zeros

大兔子大兔子 提交于 2020-01-03 03:40:17

问题


Im trying to enter a phone number into my database, the column is set as varchar(15) and inside phpmyadmin it will accept a phone number with a leading 0 (07712123123 for example).

In my PHP script i have the variable $contactNo which is a string containing 07712123123

but when I use my prepared statement to input the data into the database the leading zero is removed. How can I stop this?

// Insert data into customer_accounts
if($stmt = $mysqli -> prepare("INSERT INTO customer_accounts (username, password, firstname, lastname, email, number) VALUES (?,?,?,?,?,?)")) {
    $stmt -> bind_param("ssssss", $username, $password, $firstname, $lastname, $emailAddress, $contactNo);
    $stmt -> execute();
    $stmt -> close();
}

I have echo'd out the variable before and after the statement and the 0 is there so it must be removed as its put into the database. I'm new to prepared statements and I cant figure out what to do to fix it.

Thanks!


回答1:


The prepared statement you provide in your question has no flow, so I am guessing there is a silent conversion of datatype.

Double-check that column number is indeed of type VARCHAR. I am pretty sure you have an INT (or similar) type there instead.



来源:https://stackoverflow.com/questions/15625057/php-mysqli-prepared-statements-removing-leading-zeros

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!