看来我的代码或更具体地说,我的语法有一些问题,我尝试了所有方法,但我的尝试都没有奏效。
我更改了语法。我还重命名了我的变量并更改了它们。
这是第一个文件
<?php
// the second sign up file
class form {
public function openform($action,$method){
echo '<form action="'.$action.'" method="'.$method.'"><br>';
}
public function name($type,$name){
echo 'write your name here:<input type="'. $type .'"name="'. $name . '"><br><hr>';
}
public function input($type,$name){
echo 'please type your email here:<input type="'. $type .'"name="'. $name . '"><br><hr>';
}
public function password($type,$name){
echo 'create a password:<input type="' . $type .'"name' . $name . '"><br><hr>' ;
}
public function button($type,$name){
echo '<input type="'. $type .'"name="'. $name . '"><br><hr>';
}
public function endform(){
echo '</form>';
}
}
?>
这是第二个文件
<?php
class user{
private $id;
private $name;
private $email;
private $password;
public function setname($name){
$this->name=$name;
}
public function setemail($email){
$this->email=$email;
}
public function setpassword($password){
$this->password=$password;
}
public function getid(){
return $this->id;
}
public function inscription(){
$bdd=new PDO('mysql:host=localhost;dbname=yassine','root','');
$bdd->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$req=$bdd->prepare('insert into user (name,email,password) values(:name,:email,:password)');
$req->execute(array(
':name'=>$this->name,
':email'=>$this->email,
':password'=>$this->password,
))
;
}
}
?>
注册文件
<?php
require '../class/user.php';
$u= new user();
var_dump($_POST);
$u->setname($_POST['name']);
$u->setemail($_POST['email']);
var_dump($u);
$u->setpass($_POST['password']);
$u->inscription();
header('location:../views/login.php')
?>
<?php
include('../Core/form.php');
$F=new form();
$F->openform("../traitement/inscription.php","POST") ;
$F->name("text","name");
$F->input("text","email");
$F->password("password","password");
$F->button('submit',"botonna");
$F->endform();
?>
您在此处缺少分号:
header('location:../views/login.php')