每当我在PHP页面中输入任何数据时,它会不断添加0作为数据库。 it says 0 in the mysql table 我是一名新生,我真的不明白错误在哪里。
这是我的PHP和表单编码。
<form name="Submit" method="post" action="signupconn.php">
<p>
<input type="text" name="textfield" id="teachersname">
</p>
<p>
<input type="text" name="textfield2" id="teachersphone">
</p>
<p>
<textarea name="textarea" id="teachersadd"></textarea>
</p>
<p>
<input type="text" name="textfield3" id="teachersic">
</p>
<p>
<input type="text" name="textfield6" id="teachersqualify">
</p>
<p><input type="text" name="textfield7" id="classassigned"></p>
<p>
<input type="text" name="textfield4" id="teachersusername">
</p>
<p>
<input type="text" name="textfield5" id="teacherspassword">
</p>
<p> </p>
<p><input type="reset" value="Reset">
<input type="submit" value="Sign Up"></p>
</form>
<?php
$server="localhost"; //host Name
$username="root"; //Mysql username
$password=""; //Mysql password
$dbname="taska_ceria_"; //Database name
//Creating connection to mysqli.
$conn=new mysqli($server,$username,$password,$dbname);
//checking connection
if($conn->connect_error){
die("Connection failed" . $conn->connect_error);
}
if(isset($_POST['submit'])){
$teachersname =
mysqli_real_escape_string($conn,$_POST['teachersname']);
$teachersphone =
mysqli_real_escape_string($conn,$_POST['teachersphone']);$teachersadd
= mysqli_real_escape_string($conn,$_POST['teachersadd']);
$teachersic = mysqli_real_escape_string($conn,$_POST['teachersic']);
$teachersqualify =
mysqli_real_escape_string($conn,$_POST['teachersqualify']);
$classassigned =
mysqli_real_escape_string($conn,$_POST['classassigned']);
$teachersusername =
mysqli_real_escape_string($conn,$_POST['teachersusername']);
$teacherspassword =
mysqli_real_escape_string($conn,$_POST['teacherspassword']);
}
$sql= "INSERT INTO
teachersinfo(teachersname,teachersic,teachersphone,teachersadd,
teachersqualify,classassigned,teachersusername,teacherspassword) VALUE
('$teachersname','$teachersphone','$teachersadd','$teachersic',
'$teachersqualify','$classassigned','$teachersusername',
'$teacherspassword')";
if($conn->query($sql) === TRUE){
echo "Record Added Succesfully";
header("location:body.php");
}
else
{
echo "Error" . $sql . "<br/>" . $conn->error;
}
$conn->close();
?>
3.请别人帮助我。
答案 0 :(得分:1)
您已将id用作输入帖子,
<input type="text" name="textfield" id="teachersname">
在名称字段上使用teachersname。
<input type="text" name="teachersname" id="teachersname">
然后它可以正常工作