Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 致命错误:未捕获错误:对字符串i调用成员函数bindParam()_Php_Mysql_Pdo - Fatal编程技术网

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

Php 致命错误:未捕获错误:对字符串i调用成员函数bindParam(),php,mysql,pdo,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}

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

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注册码是fallows

<?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";
}
}
?>

有人能帮我解决这个问题吗谢谢你你必须在准备好的语句上绑定参数。将select查询语句更改为

$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!";
}

您并不是在声明语句,而是直接绑定参数以进行查询

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

$select=$connection->prepare$query,然后是$select->bindParam':username',$username谢谢你的回答它成功了,但它有一个问题它甚至用同一封电子邮件多次注册这个人,但根据我写的代码,它不应该这么做,它只需要创建一个带有特定电子邮件的帐户。如果statment更改为count1,请检查它和计数,但我找不到错误在哪里更改$query->rowCount;到$query->FETCHTCOLUMN然后tryit即使现在也不起作用,但我不明白有什么区别以前我创建了l used rowCount,然后它起作用了,但现在它不起作用了,而且还使用了FETCHTCOLUMN,但不起作用它正在成功地注册到数据库中