PHP does not recognize the table in my database

0

my base is: test, my table: user, inside the table I have two users name and password, when I enter the correct name and password for the user to accept a message of success, but I get this message

  

Connection error SQLSTATE [42S02]: Base table or view not found: 1146 Table 'test.user' does not exist ...

it tells me that the user table does not exist in the database, it tries when it is --- who can give me a solution to this

try{

    $base=new PDO('mysql:host=localhost;dbname=prueba','root','');


    $base->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


    $sql="select * from prueba.usuario WHERE usuario= :nom AND contrasena= :contra ";


    $resultado=$base->prepare($sql);


    $login=htmlentities(addslashes($_POST["nom"]));
    $pasword=htmlentities(addslashes($_POST["contra"]));


    $resultado->bindValue(":nom", $login);
    $resultado->bindValue(":contra", $pasword);

     //ejecutamos la funcion sql
     $resultado->execute();

     $numero_registro=$resultado->rowCount();

     if ($numero_registro !=0) {
     echo "<h2>Estas Registrado</h2>";

     } else {
         header("location:diseño_IngresoA1.php");
         exit();
     }     
}catch(Exception $e){
    die("Error conexion" . $e->getMessage());
} 
?>
    
asked by Ramon 29.04.2018 в 01:50
source

1 answer

0

First I recommend that you be more orderly when asking questions, and put the code well so that it can be understood, and your question is not wrong.

Now, I recommend you use only the name of the table in the query, you're supposed to be connected to the test database.

That you use the MySQL clauses in capital letters.

Use the bindParam method to bind the data.

Try this:

try
 { 
  $base=new PDO('mysql:host=localhost;dbname=prueba','root','');
  $base->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $sql="SELECT * FROM usuario WHERE usuario = :nom AND contrasena= :contra";

  $resultado=$base->prepare($sql);

  $login=htmlentities(addslashes($_POST["nom"]));
  $pasword=htmlentities(addslashes($_POST["contra"]));

  $resultado->bindParam(":nom", $login);
  $resultado->bindParam(":contra", $pasword);

  // ejecutamos la funcion sql 
  $resultado->execute();

  $numero_registro=$resultado->rowCount();

  if($numero_registro>0){
   echo "<h2>Estas Registrado</h2>";
  } else {
   header("location:diseño_IngresoA1.php");
   exit();
  }
 }catch(Exception $e){
  die("Error conexion" . $e->getMessage());
 }
?>
    
answered by 29.04.2018 в 03:07