I want to insert a phone number to a database.
My problem now is, how to add a +
character to the variable and save it to the database?
This is my form :
<form action="proccess.php" method="POST">
<input type="number" name="number">
<button type="submit">Send!</button>
Dnd this is process.php
:
<?php
$phone = $_POST['number'];
$save = mysql_query("INSERT INTO phonenumber VALUES('$phone')");
?>
So I want to insert the data to be +111111111
for example.
<?php
$phone = "+" . $_POST['number'];
$save = mysql_query("INSERT INTO phonenumber VALUES('$phone')");
?>
Additionally, consider using the newer mysqli_
-functions.
Consider using 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));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.