<?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>";}
}
}
}
&GT;
致命错误:未捕获的异常&#39; PDOException&#39; with message&#39; SQLSTATE [HY093]:参数号无效:绑定变量的数量与令牌的数量不匹配&#39;在/opt/lampp/htdocs/project/log/user.php:51堆栈跟踪:#0 /opt/lampp/htdocs/project/log/user.php(51):PDOStatement-&gt; execute()#1 / opt / lampp / htdocs / project / log / registration.php(9):user-&gt; userRegistration(Array)在第51行的/opt/lampp/htdocs/project/log/user.php中抛出的#{{}} 请帮帮我....
答案 0 :(得分:0)
您在SQL上指定了5个参数:
:name,:username,:email,:password,:gender
但你只是绑定3:
$query->bindValue(':name',$name);
$query->bindValue(':email',$email);
$query->bindValue(':password',$password);