输入表单代码是
<form method="post" action="display.php" id="register-form" name="register-form" onsubmit="function() return false;">
<center> First Name :<pre> <input type = "text" name="firstname" value="" ></pre><br>
Last Name:<pre><input type="text" name = "lastname" value="" ></pre><br>
State:<pre><input type="text" name = "state" value="" ></pre><br>
City:<pre><input type="text" name = "city" value="" ></pre><br>
Mobile No:
<pre>
<input type="tel" id = "mobileno" name = "mobileno" data-validation="number" value="" ></pre><br>
Gender :<pre><ul type="none">
<li>Male: <input type="radio" name="icheck" value="Male">
Female: <input type="radio" name="icheck" value="Female" checked></li></ul></pre>
<input type="submit" name="add" value="ADD" formaction="add.php">
<input type="submit" name="delete" value="DELETE">
<input type="submit" name= "update" value="UPDATE" formaction="display.php"> </center>
</form>
add.php(file)(从表单中插入值)
include("dbconnect.php");//database connect
$firstname =$_POST['firstname'];
$lastname = $_POST['lastname'];
$state = $_POST['state'];
$city = strip_tags($_POST['city']);
$gender = strip_tags($_POST['icheck']);
$mobileno = (int) $_POST['mobileno'];
$query = "INSERT INTO user(LastName,FirstName,State,City,MobileNo,Gender) VALUES(?,?,?,?,?,?)";
$stmt=mysqli_prepare($dbc,$query) or die(mysqli_error());
$bind='ssssis';
mysqli_stmt_bind_param($stmt,$bind,$lastname,$firstname,$state,$city,$mobileno,$gender);
mysqli_stmt_execute($stmt);
if (mysqli_stmt_affected_rows($stmt) ==
1) {
echo '<p>Your message has been
posted.</p>';
} else {
echo '<p style="font-weight: bold;
color: #C00">Your message could not
be posted.</p>';
echo '<p>' . mysqli_stmt_error($stmt) .
'</p>';
}
// Close the statement:
mysqli_stmt_close($stmt);
mysqli_close($dbc);
为mobileno输入的值是7878787878,在数据库中它显示为2147483647 第二次我输入的值是8787878787,它显示相同的值。
因此代码仅显示dimatch手机号码的错误。 谢谢!!
答案 0 :(得分:2)
参数不匹配并删除手机号码前面的int
$query = "INSERT INTO user(LastName,FirstName,State,City,MobileNo,Gender) VALUES(?,?,?,?,?,?)";
mysqli_stmt_bind_param($stmt, $bind, $lastname, $firstname, $state, $city, $mobileno, $gender);
答案 1 :(得分:0)
更改
$bind = 'ssssis';
到
$bind = 'ssssds';