PHP变量中的特殊字符


Special Character in PHP variable?

我想在数据库中插入一个电话号码。

我现在的问题是,如何将+字符添加到变量并将其保存到数据库?

这是我的表单:

<form action="proccess.php" method="POST">
<input type="number" name="number">
<button type="submit">Send!</button>

这是process.php:

<?php
$phone = $_POST['number'];
$save = mysql_query("INSERT INTO phonenumber VALUES('$phone')");
?>

所以我想插入数据为+111111111例如

<?php
$phone = "+" . $_POST['number'];
$save = mysql_query("INSERT INTO phonenumber VALUES('$phone')");
?>

另外,考虑使用较新的mysqli_ -函数。

考虑使用PDO。

$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$phone = '+'.$_POST['number'];
$sql = "INSERT INTO phonenumber (phone) VALUES (:phone)";
$q = $conn->prepare($sql);
$q->execute(array(':phone'=>$phone));