我收到错误说我的电子邮件变量是空的,除了我的正则表达式有问题,这似乎是字符类中的范围乱序,我想这是一个愚蠢的错误,因为我有很多东西要学
<?php
include_once('../resources/config.php');
class register
{
private $username;
private $password;
private $passmd5;
private $email;
private $errors;
private $token;
private $db;
public function __construct()
{
$this->db = new config();
$this->db = $this->db->dbConnect();
$this->errors = array();
$this->username = $this->regex($_POST['user']);
$this->password = $this->regex($_POST['pass']);
$this->email = $this->regex($_POST['email']);
$this->token = $this->regex($_POST['token']);
$this->passmd5 = md5($this->password);
}
public function process()
{
if($this->valid_token() && $this->valid_data())
$this->register();
}
public function regex($var)
{
$reggie = preg_replace('/[^a-zA-ZO-90.]/','',$var);
return $reggie;
}
public function register()
{
$this->db->prepare("insert into users(name, pass) values ('($this->username)','($this->passmd5)')");
if(rowCount() < 1)
$this->errors() == "form has failed you";
}
public function show_errors()
{
foreach ($this->errors as $key => $value) {
echo $value."</br>";
}
}
public function valid_data()
{
if(empty($this->username))
$this->errors() == 'invalid username';
if(empty($this->password))
$this->errors() == 'invalid password';
if(empty($this->email) || !ereg('/^[^\W][a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\@[a-zA-Z0-9_]+(\.[a-zA-Z0-9_]+)*\.[a-zA-Z]{2,4}$/', $this->email))
$this->errors() == 'invalid email';
return count ($this->errors)? 0:1;
}
public function valid_token()
{
}
}
?>
$obj_reg = new register();
if($obj_reg->process())
{
echo 'succes';
}else
{
$obj_reg->show_errors();
}
}
$token = $_SESSION['token'] = md5(uniqid(mt_rand(), true));
?>
<form method="post" action="index.php?page=register.php" >
<table>
<tr><td>username:</td><td> <input type="text" name="user"/></td></tr>
<tr><td>password:</td><td> <input type="password" name="pass"/></td></tr>
<tr><td>email:</td><td> <input type="text" name="email"/></td></tr>
</table>
<input type="hidden" name="token" value="<?=$token;?>"/>
<input type="submit" name="register" value="register"/>
</form>