我一直在用PHP编写注册表单。完成代码后,它运行完美,没有任何错误(它表示“refistration not successfull”)但是用户信息没有存储在我创建的数据库中。完整代码如下:
Process.php:
<?php
class db{
public $host = "localhost";
public $user = "root";
public $pass = "";
public $db_name = "oop";
public $link;
public function __construct(){
$this->connect();
}
private function connect(){
$this->link = new mysqli($this->host,$this->user,$this->pass,$this->db_name);
}
public function insert($query){
$result = $this->link->query($query);
if($result){
echo "<center><h2>Registration successful</h2></center>";
}
else{
echo "<center><h2>Registration not successful</h2></center>";
}
}
}
?>
form.php的:
<h2>Registration Form</h2>
<form method="post" action ="form.php">
<label>User Name</label>
<input type = "text" name = "name" placeholder="Enter user name" required="required"></input>
<label>User Email</label>
<input type = "text" name = "email" placeholder="Enter user Email" required="required"></input>
<label> User Password</label>
<input type = "password" name = "pass" placeholder="Enter password" required ="required"></input>
<input type = "submit" name = "signup" value = "Sign Up"></input>
</form>
<?php
include "process.php";
$db = new db();
if(isset($_POST['signup'])) {
$user = $_POST['name'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$query = "INSERT INTO users(user_name,user_email,user_pass) VALUES('$user','$email','$pass')";
$db->insert($query);
}
?>
帮助解决这个问题。