I'm doing a login window and when I count the number of rows affected by the SELECT statement to validate the account and the password I have a problem.
Error: SQLSTATE[HY000]: General error: 1008 OCIStmtExecute: ORA-01008: not all variables bound (ext\pdo_oci\oci_statement.c:159)
Here is the problem (I did this because I need count number of rows when i do SELECT. All this is to login.)
I found this piece of code in Official page of PHP: Page PHP link (Example number 2)
$resultado = $base->query($sql);
if ($resultado) {
/* Comprobar el número de filas que coinciden con la sentencia SELECT */
if ($resultado->fetchColumn() > 0) {
/* Ejecutar la sentencia SELECT real y trabajar con los resultados */
echo "<h2>Adelante!!</h2>";
}
/* No coincide ningua fila -- hacer algo en consecuencia */
else {
print "Ninguna fila coincide con la consulta.";
}
}
CODE:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
try
{
$base = new PDO('oci:dbname=localhost', 'hr', 'hr');
$base->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql= "SELECT * FROM DEPARTMENTS WHERE DEPARTMENT_ID=:login AND MANAGER_ID=:password";
$resultado = $base->prepare($sql);
$login = htmlentities(addslashes($_POST["login"]));
$password = htmlentities(addslashes($_POST["password"]));
$resultado->bindValue(":login", $login);
$resultado->bindValue(":password", $password);
$resultado->execute();
$resultado = $base->query($sql);
if ($resultado) {
if ($resultado->fetchColumn() > 0) {
echo "<h2>Adelante!!</h2>";
}
else {
print "Ninguna fila coincide con la consulta.";
}
}
}
catch(Exception $e)
{
die("Error: " .$e->getMessage());
}
?>
</body>
</html>