Snowcat Jung Snowcat Jung - 6 months ago 80
SQL Question

Uncaught PDOException: SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)

I got error like.

Uncaught PDOException: SQLSTATE[21000]: Cardinality violation: 1241 Operand should contain 1 column(s)

if ($_POST['submit'] ?? '' == "Log In") {

$query = "SELECT * FROM member WHERE (email, password) LIKE (:email, :password)";

$stmt = $link -> prepare($query);
$stmt -> bindValue(':email', $_POST['loginemail'], PDO::PARAM_STR);
$stmt -> bindValue(':password', md5(md5($_POST['loginemail']).$_POST['loginpassword']), PDO::PARAM_STR);
$stmt -> execute();
$rows = $stmt -> fetchAll();

}


but There's no error in this statement.

$sql = "SELECT ko_name FROM dogBREEDS WHERE dogBREEDS.ko_name LIKE (:keyword) ORDER BY id ASC LIMIT 0, 10";
$query = $pdo->prepare($sql);
$query->bindParam(':keyword', $keyword, PDO::PARAM_STR);
$query->execute();
$list = $query->fetchAll();


How can I solve this? and What's the difference??

Answer

$query = "SELECT * FROM member WHERE (email, password) LIKE (:email, :password)";

This sql is not a right sql in correct syntax. LIKE(or take a look of here MySQL LIKE Clause) can not be used like this, try this please;)

$query = "SELECT * FROM member WHERE email LIKE (:email) and password LIKE (:password)";
Comments