致命错误:未捕获错误:在字符串i上调用成员函数bindParam()

时间:2017-07-09 05:39:09

标签: php mysql pdo

我正在尝试创建一个注册页面并成功创建它,并希望仅将其验证为一个电子邮件帐户,以便用户只能通过电子邮件创建一个帐户一次,并且下次它应该发出错误说明您已经已经在电子邮件帐户中注册但在路径中我得到了一个错误,说明了这个错误

Fatal error: Uncaught Error: Call to a member function bindParam() on string 
in C:\xampp\htdocs\sign\register.php:20 Stack trace: #0 {main} thrown in 
C:\xampp\htdocs\sign\register.php on line 20

我的php注册码就像休闲一样

<?php
include('connection.php');  
$form = $_POST;
$username = $form['username'];
$password = $form['password'];
$repass = $form['repass'];
$email = $form['email'];
$date = $form['date'];
$month = $form['month'];
$year = $form['year'];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email please type a valid one"; 
}
else{
if($username !='' && $password !='' && $repass!='' && $email !='' && 
$date!='' && $month !='' && $year !='')
{
if($password == $repass)
{
$query = "SELECT * FROM users where email = :email AND username = 
:username";
$query->bindParam(':username',$username);
$query->bindParam(':email',$email);
$count1 = $query->rowCount();
if($count> 0)
{
    echo "soryy the email you are trying to register is already 
registered!";
}
else{

$insert = $connection->prepare("INSERT INTO users 
(username,password,email,date,month,year)  values (:username, :password, 
:email, :date, :month, :year)");
$insert->bindParam(':username',$username);
$insert->bindParam(':password',$password);
$insert->bindParam(':email',$email);
$insert->bindParam(':date',$date);
$insert->bindParam(':month',$month);
$insert->bindParam(':year',$year);
$out = $insert->execute();
if(isset($out)){
    echo "thankyou you have sucessfully registered";
}
else{
    echo " sorry some error occured please try again!";
}
} 
}
else{
echo " passwords do not match";
die();
}
}
else{
echo " you have not filled the registration form completely so please it";
}
}
?>

任何人都可以帮助我解决问题而不是

2 个答案:

答案 0 :(得分:1)

你没有声明一个声明并直接绑定params来查询使用这样的东西。

$select = $connection->prepare($query); 
$select->bindParam(':username',$username);

答案 1 :(得分:0)

你必须在准备好的声明中绑定params。将选择查询语句更改为

$query = $connection->prepare("SELECT * FROM users where email = :email AND username = 
:username");

修改

要计算选择查询的行数,请使用fetchColumn。您还要为$count1分配值并使用$count。所以使用相同的变量名称

$count = $query->fetchColumn();
if($count> 0)
{
    echo "soryy the email you are trying to register is already 
registered!";
}