[英]data not inserted successfully to DB
html文件(aa.html):
<!DOCTYPE html>
<html>
<head>
<title>RegPage</title>
</head>
<body>
<form action ="bb.php" method="post">
name: <input type="text" name "username">
<br/>
email: <input type="text" name ="email">
<br/>
password: <input type="password" name="password">
<input type = "submit" value = "insert">
</form>
</body>
</html>
php文件(bb.php):
<?php
$con=mysqli_connect('localhost','root','');
if(!con)
{
echo 'not connected to server';
}
if (!mysqli_select_db ($con,'pilot'))
{
echo 'database not selected';
}
$name=$_post['username'];
$email=$_post['email'];
$password=$_post['password'];
$sql="insert into dbinvestor (email,password,name) values ('$email','$password', '$name')";
if (!mysqli_query($con,$sql))
{
echo 'not inserted';
}
else
{
echo 'inserted succesfuly';
}
header ("refresh:2;url=aa.html");
?>
数据库和表: DB
输出: OutPut
不知道如何解决,谢谢帮助!
未定义的索引username
应该是您在PHP方面的错误。
name: <input type="text" name "username">
一定是 :
name: <input type="text" name="username">
然后在服务器端也使用准备好的语句。
然后,您还有另一个错误:
if(!con)
未定义常量con
应该是:
if(!$con)
最后,不要以纯文本形式存储密码,请使用password_hash()和password_verify()
<?php
$con=mysqli_connect('localhost','root','');
if(!$con)
{
echo 'not connected to server';
}
if (!mysqli_select_db ($con,'pilot'))
{
echo 'database not selected';
}
$name=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['password'];
//hash password
$hash = password_hash($password,PASSWORD_DEFAULT);
$sql="insert into dbinvestor (email,password,name) values (?,?,?)";
$stmt = $con->prepare($sql);
$stmt->bind_parm("sss",$email,$hash,$name);
if($stmt->execute()){
echo 'inserted succesfuly';
}else{
echo 'not inserted';
echo $stmt->error;
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.