For some reason when I use preg_replace() for a input field that stores phone numbers, I can’t store it into MySQL. Can preg_replace be used for integers or can it only be used for strings?
I am trying to make it impossible to input letters into the text field.. Can someone give some insight?
$tel = $_POST['tel'];
//when I use preg_replace, it doesn’t store the value in MySQL
$tel = preg_replace($reg_num,'', $tel);
…
$st->bindParam(6, $tel, PDO::PARAM_INT);
preg_replacewill cast the Integer as a String, and perform the replace correctly. However, it will return a String wherebindParamis expecting an Integer.Storing a phone number as an Integer is usually ill-advised as you would lose any leading ‘0’ or any ‘+’ sign (if used for international numbers).