Login to bootstrap modal

Asked

Viewed 299 times

0

I created a login button in the site navbar, when the user clicks opens a modal with the login form. In the navbar php file I am calling the file "validaLogin.php" to check the user data and store it in a session variable, but when I submit another form on another page, it submits the two forms, for example, on the contact page, has a form, and when clicking submit in the form, it submits in both, but as the page does not exist the variables of the login form gives the following error:

"Notice: Undefined index: login in C: xampp htdocs Clinicamedica php validalogin.php on line 13

Notice: Undefined index: password in C: xampp htdocs Clinicamedica php validalogin.php on line 14"

validaLogin.php:

<?php
session_start();
include("conexaoMysql.php");

function filtraEntradaV($dado){
    $dado = trim($dado);
    $dado = stripslashes($dado);
    $dado = htmlspecialchars($dado);
    return $dado;
};  

if($_SERVER["REQUEST_METHOD"] == 'POST'){
    $login = filtraEntradaV($_POST["login"]);
    $senha = filtraEntradaV($_POST["senha"]);


    $sql = "SELECT Login FROM clinicamedica.usuario where Login = '$login' and Senha = '$senha' ";
    $resultado = $conn->query($sql);

    if($resultado->num_rows <= 0){
        echo "<script>alert('Dados incorretos')</script>";}
    else
        $_SESSION["login"] = $login;

}


?>

contact page:

<?php
include("conexaoMysql.php");

function filtraEntradaC($dado){
    $dado = trim($dado);
    $dado = stripslashes($dado);
    $dado = htmlspecialchars($dado);
    return $dado;
}   

if($_SERVER["REQUEST_METHOD"] == 'POST'){
    $msgErro = '';
    $nome = $email = $motivo = $mensagem = "";


    $nome = filtraEntradaC($_POST["nome"]);
    $email = filtraEntradaC($_POST["email"]);
    $motivo = filtraEntradaC($_POST["motivo"]);
    $mensagem = filtraEntradaC($_POST["mensagem"]);

    try{


        $sql = "
            INSERT INTO clinicamedica.contato(Id, Nome, Email, Motivo, Mensagem)
            values (null, ? , ? , ? , ?);
        ";

        $stmt = $conn->prepare($sql);

        $stmt->bind_param("ssss", $nome , $email , $motivo , $mensagem);

        if (! $stmt->execute())
            throw new Exception("Erro ao realizar o contato: " . $conn->error);


        $formProcSucesso = true;
        } catch (Exception $e){
            $msgErro = $e->getMessage();
        }
}
?>

How can I solve?

  • I edited your code above, in the file validaLogin.php was without closing the if, try to copy and paste this edited file in your file and check what returns, in case there is an error posted a reply to help you

  • I changed the action form action="<? php echo htmlspecialchars($_SERVER["PHP_SELF"]); to action="php/cadastrocont.php" that worked. Vlw!!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.