2 votes

PHP: Error: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

I am making a Login method but I can't solve this error, I would appreciate your help.

<?php
  try {
    $base = new PDO("mysql:host = localhost; dbname = estimasoft", "root", "");
    $base->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "SELECT * FROM usuario WHERE nombre = :nombre AND contraseña = :contraseña";
    $resultado = $base->prepare($sql);
    $nombre = htmlentities(addslashes($_POST["nombre"]));
    //echo $nombre;
    $contraseña = htmlentities(addslashes($_POST["contraseña"]));
    $resultado->bindValue(':nombre', $nombre);
    $resultado->bindValue(':contraseña', $contraseña);
    $resultado->execute();
    $numeroRegistro = $resultado->rowCount();
    if($numeroRegistro == 1){
        echo "adelante";
    }else{
      header("location: ../index1.php");
    }
} catch (Exception $e) {
    die("Error: ".$e->getMessage());
}
?>

and the form is this :

<form class="container col-lg-4 col-lg-offset-4" action="sistema/comprueba_login.php" method="post">
    <div class="form-group">
         <label for="user">Usuario:</label>
         <input class="form-control" type="text" name="nombre" value="" id="user" placeholder="Usuario">
    </div>
    <div class="form-group">
         <label for="password">Contraseña:</label>
         <input class="form-control" type="password" name="contraseña" value="" id="password" placeholder="Contraseña">
   </div>
   <div class="row">
        <input class="btn btn-default col-lg-4 col-lg-offset-4" type="submit" name="name" value="Ingresar">
   </div>
</form>

2 votes

It may be because of the name of the password column, it is possible that it is not recognizing the letter ñ in ':password'.

1 votes

I will try it thanks :D

1 votes

Try it and then tell us how it went.

3voto

Juan Pinzón Points 6688

Based on the comments the error

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

It may be because of the name of the password column, it is possible that it is not recognizing the letter ñ in ':password'.

and the error

SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected

is due to the database name, check if the database name is spelled correctly in your PDO connection string.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X