0
Hello, I’m trying to make the user ID appear in the url when they log in. I made a function that receives the login and password of the user and returns the ID. However, when the user logs in, the ID that shows in the URL is always '0'. Independent of users who log in.
index php.
<form method="POST" action="conteudo.php" name="logar">
<fieldset>
<label>
<input type="text" name="usuario" placeholder="LOGIN"/>
</label>
<br><br>
<label>
<input type="password" name="pass" placeholder="SENHA"/>
</label><br><br>
<input type="submit" name="enviar" value="ACESSAR"/>
<input type="submit" name="cadastrar" value="CADASTRAR"/>
</fieldset>
</form>
php content.
if($_POST['enviar']){
$login = $_POST['usuario'];
$senha = sha1($_POST['pass']);
if(verificaUsuario($conexao,$login,$senha)){
$id = pegandoID($conexao,$login,$senha);
header("Location: principal.php?id={$id}");PASSANDO ID PARA URL AQUI
}elseif(!verificaUsuario($conexao,$login,$senha)){
header("Location:index1.php?erro=#");
}
}elseif($_POST['cadastrar']){
header("Location: cadastro.php");
}
php bank.
include "config/config.php";
try{
$conexao = new PDO("mysql:host={$servidor};port=3306;dbname={$banco}",$usuario,$senha);
}catch(PDOException $error){
echo "Erro: " . $error->getMessage() . "<br>";
die();
}function pegandoID($conexao,$login,$senha){
$sql = $conexao->exec("SELECT id FROM usuarios WHERE login='$login' AND senha='$senha'");
return $sql;}
The method
exec
PDO will not return theid
selected; instead, use thequery
.– Woss
I changed it, but then the error Catchable fatal error appears: Object of class Pdostatement could not be converted to string in C: xampp htdocs php phpoo Testes conteudo.php on line 11. Line 11, is the line of the first header
– Guilherme Wayne
It is not just a text change, so I have Linked the respective documentation. Read each one and understand how it works.
– Woss
I could not resolve the error. The ID 0 continues to appear in the url.
– Guilherme Wayne