【发布时间】:2017-01-13 05:41:52
【问题描述】:
<?php
include_once 'session.php';
include 'database.php';
class user{
private $db;
public function __construct(){
$this->db= new Database();
}
public function userRegistration($data){
$name = $data['name'];
$email = $data['email'];
$password = md5($data['password']);
$chk_email = $this->emailCheck($email);
if($name == "" or $email == "" or $password == "" ){
$msg = "<div class = ' alert alert-danger'><strong>Error !</strong>Field must not be empty</div>" ; //bootstrap aleart massage
return $msg;
}
if(filter_var($email,FILTER_VALIDATE_EMAIL)=== false){ // email validate
$msg = "<div class ='alert alert-danger'><strong>Error ! </strong>Email address is not valid</div>";
return $msg;
}
if ($chk_email==true){
$msg = "<div class ='alert alert-danger'><strong>Error ! </strong>This email is already exist</div>";
return $msg;
}
$sql = "INSERT INTO register_tbl(name,username,email,password,gender) VALUES(:name,:username,:email,:password,:gender)";
$query = $this->db->pdo->prepare($sql);
$query->bindValue(':name',$name);
$query->bindValue(':email',$email);
$query->bindValue(':password',$password);
$result=$query->execute();//problem is here ..
if($result){
$msg = "<div class = 'alert alert-success'><strong>Success .</strong>You have register now.</div>";
return $msg;
}else{
$msg = "<div class = 'alert alert-danger'><strong>Sorry !</strong>Some thing is not right</div>";
}
}
public function emailCheck($email){
$sql = "SELECT email FROM register_tbl WHERE email = :email ";
$query = $this->db->pdo->prepare($sql ); // prepare() is the method of PDO class;
$query->bindValue(':email',$email); //bindValue() is the method of PDO class;
$query->execute();
if($query->rowCount()>0){
return true;
}else{
return false;
}
}
public function getLoginUser($email,$password){
$sql = "SELECT * FROM register_tbl WHERE email = :email AND password = :password LIMIT 1";
$query = $this->db->pdo->prepare($sql ); // prepare() is the method of PDO class;
$query->bindValue(':email',$email); //bindValue() is the method of PDO class;
$query->bindValue(':password',$password);
$query->execute();
$result = $query->fetch(PDO::FETCH_OBJ);
return $result;
}
public function userLogin($data){
$email = $data['email'];
$password = md5($data['password']);
if( $email == "" or $password == "" ){
$msg = "<div class = ' alert alert-danger'><strong>Error !</strong>Field must not be empty</div>" ; //bootstrap aleart massage
return $msg;
}
if(filter_var($email,FILTER_VALIDATE_EMAIL)=== false){ // email validate
$msg = "<div class ='alert alert-danger'><strong>Error ! </strong>Email address is not valid</div>";
return $msg;
if ($chk_email==true){
$msg = "<div class ='alert alert-danger'><strong>Error ! </strong>This email is not exist</div>";
return $msg;
}
$result = $this->getLoginUser($email,$password);
if($result){
Session :: init();
Session :: setinit('login',true);
Session :: setinit('id',$this->id);
Session :: setinit('name',$this->name);
Session :: setinit('username',$this->username);
Session :: setinit('loginmsg',"<div class ='alert alert-success'><strong>Success ! </strong>You are login.</div>");
header('index.php');
}else{echo "<script class = 'alert alert-danger'><strong>Error</strong>some thing wrong</script>";}
}
}
}
?>
致命错误:未捕获的异常“PDOException”和消息“SQLSTATE[HY093]:无效的参数编号:绑定变量的数量与 /opt/lampp/htdocs/project/log/user.php 中的标记数量不匹配”: 51 堆栈跟踪:#0 /opt/lampp/htdocs/project/log/user.php(51):PDOStatement->execute() #1 /opt/lampp/htdocs/project/log/registration.php(9): user->userRegistration(Array) #2 {main} 在第 51 行的 /opt/lampp/htdocs/project/log/user.php 中抛出 请帮帮我....
【问题讨论】:
-
参数计数错误。就这么简单。
-
$query->bindValue(':gender',$gender);+ 用户名相同。这就是错误消息告诉您的内容。 (编辑:两者都还没有定义) -
3 不等于 5
-
并且不要使用 md5
标签: php