Ошибка при попытке проверить, существует ли электронная почта в БД - PullRequest
0 голосов
/ 23 февраля 2012

Я получаю эту ошибку, когда пытаюсь проверить, существует ли электронное письмо в базе данных, и не уверен, почему:

Неустранимая ошибка: вызов функции-члена bind_param () для необъекта в ""

Вот мой код:

$email = $_POST['email'];
//prepare and set the query and then execute it
$stmt = $conn2->prepare("SELECT COUNT (*) FROM users WHERE email = ?");
$stmt->bind_param('s', $email);
$stmt->execute();

// grab the result
$stmt->store_result();

// get the count
$numRows = $stmt->num_rows();

if( $numRows )
{

echo "<p class='red'>Email is already registered with us</p>";
}
else


//if we have no errors, do the SQL

У меня есть отдельный файл подключения к базе данных:

function DB2($host='', $user='', $password='', $db='') {

     /* Create a new mysqli object with database connection parameters */
     $mysqli = new mysqli($host, $user, $password, $db);

     if(mysqli_connect_errno()) {
        echo "Connection Failed: " . mysqli_connect_errno();
        exit();
     }    

     return $mysqli;
  }

, который связан с этим файлом с помощью:

$conn2 = DB2();

1 Ответ

0 голосов
/ 23 февраля 2012

Вы не сказали, на каком это языке. Я предполагаю, что это perl и dbi.

$email = $_POST['email'];
//prepare and set the query and then execute it
$stmt = $conn2->prepare("SELECT COUNT (*) FROM users WHERE email = ?");
$stmt->bind_param($email);
$stmt->execute();

должно быть

$email = $_POST['email'];
//prepare and set the query and then execute it
$stmt = $conn2->prepare("SELECT 1 FROM users WHERE email = ? fetch first row only");
$stmt->execute($email);

Я не знаю, что такое store_result (). Я не думаю, что это часть DBI. Возможно, вы захотите сделать:

@found = $stmt->selectrow_array();
if ($#found) { #email was found }
...