Number of variables doesn't match number of pa

2019-07-21 23:12发布

So according to a suggestion I am trying to include prepared statements.

But PHP doesn't accept my code.

$stmt = $link->prepare('SELECT COUNT(*) FROM `table` WHERE `company` = CONVERT( _utf8 \'?\' USING latin1 )  COLLATE latin1_german1_ci AND `password` = CONVERT( _utf8 \'?\' USING latin1 ) COLLATE latin1_german1_ci');
$stmt->bind_Param('ss',  $firmaP, $kennwP);
$firmaP = utf8_encode($_POST['company']);
$kennwP = utf8_encode($_POST['password']);
if ($stmt->execute()) {
  if($row = $stmt->fetch()) {
      echo "OK";
    }
    else
    {
      echo "NO";
    }
}

I get

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

Whereas I have two questionmarks in the query and two variables in bind_Param.

How to solve this?

EDIT: Replacing \'?\' with ? leads to

Fatal error: Call to a member function bind_param() on a non-object

标签: php mysqli
1条回答
三岁会撩人
2楼-- · 2019-07-21 23:53

Don't quote your ?s as follows:

$stmt = $link->prepare('SELECT COUNT(*) FROM `table` WHERE `company` = CONVERT( _utf8 ? USING latin1 )  COLLATE latin1_german1_ci AND `password` = CONVERT( _utf8 ? USING latin1 ) COLLATE latin1_german1_ci');
$firmaP = utf8_encode($_POST['company']);
$kennwP = utf8_encode($_POST['password']);
$stmt->bind_Param('ss',  $firmaP, $kennwP);
if ($stmt->execute()) {
  if($row = $stmt->fetch()) {
      echo "OK";
    }
    else
    {
      echo "NO";
    }
}
查看更多
登录 后发表回答