1
I’m new with PHP and would like to ask a question:
In the code that I will show below, has been tested the consultation in the bank until the try
, the problem is that after the try(){}
the prepare does not return me anything, I tested with the die('');
and he only returns to me echo
and only goes so far.
Follow the login.php code
<?php
require_once("connect.php");
//recuperar dados
if(isset($_POST['logar'])){
echo 'clciou</br>';
echo $usuario= trim(strip_tags($_POST['usuario']));
echo $senha= trim(strip_tags($_POST['senha']));
$select="SELECT*FROM login WHERE usuario=:usuario AND senha=:senha";
echo $contar = $selec-> rowCount();
try{
$result = $conexao ->prepare($select);
$result -> bindParam(':usuario',$usuario,PDO::PARAM_STR);
$result -> bindParam(':senha',$senha,PDO::PARAM_STR);
$result -> execute();
}
catch(PDOException $e){
echo $e;
}
}
?>
Form he picks up
<form action="#" method="post" enctype="multipart/form-data">
<h1>Faça seu Login</h1>
<div class="login-fields">
<p>Entre com seus dados:</p>
<div class="field">
<label for="username">Usuário:</label>
<input type="text" id="username" name="usuario" value="" placeholder="Usuário" class="login username-field" />
</div>
<!-- /field -->
<div class="field">
<label for="password">Senha:</label>
<input type="password" id="password" name="senha" value="" placeholder="Senha" class="login password-field" />
</div>
<!-- /password -->
</div>
<!-- /login-fields -->
<div class="login-actions">
<input type="submit" name="logar" value="entrar no sistema" class="button btn btn-success btn-large" />
</div>
<!-- .actions -->
</form>
Could someone tell me what I do wrong?
See if there are any errors:
if(! $result -> execute()){ print_r($result->errorInfo());
– rray
I edited the post to make it easier to understand.
– MarceloBoni
Thank you Father, but so, I used and he did not inform me anything.
– Harakin Cheech
The error was this : Fatal error: Call to a Member Function prepare() on null in /var/www/html/Chris/login.php
– Harakin Cheech
You have prompted $connected ? in case it should be an instance of PDO, have how to put as this the class connect.php?
– Mauricio Wanderley Martins
Hello boy! What’s this for? " echo $usuario= Trim(strip_tags($_POST['user']));" and that? " echo $password= Trim(strip_tags($_POST['password']));" Do you want to use the variable or print it? The right would be: $usuario= Trim(strip_tags($_POST['usuario'])); and $password= Trim(strip_tags($_POST['password']));
– user58118