Error Login System

Asked

Viewed 57 times

-4

I’m trying to create a login system, but the system is not logging in with registered users, I tried to create a condition where only users register can access the login.

Error:

Warning: mysql_query() expects parameter 1 to be string, resource given in C:\xampp\htdocs\Controla\logando.php on line 10

Notice: Use of undefined constant linha - assumed 'linha' in C:\xampp\htdocs\Controla\logando.php on line 13
Erro no Login!
voltar

Code:

<?php    
include 'conexao.php';
?>

<?php

$email = $_POST['emaillogin'];
$senha = $_POST['senhalogin'];
$sql = ("SELECT * FROM tb_usuarios WHERE email_usuario='$email' and senha_usuario='$senha'");
$result = mysql_query($con,$sql);
$linha = mysql_affected_rows($con);

if(linha > 0)

    $num=rand(1000000,9000000);
    setcookie("num_login",$num);
    header("Location:bemvindo.php?num1=$num");

else

    echo"Erro no Login!</br>";
    echo"<a href=login.php>voltar</a>";



mysql_close($con);

?>
<?php
include 'conexao.php';

?>

<?php
if(isset($COOKIE['$num_login']))

    $n1=$_GET['num1'];
    $n2=$_COOKIE['num_login'];

    if($n1 != $n2)

        echo"login não efetuado";
        exit;



else

    echo"login não efetuado";
    exit;




echo"Pagina inicial";


mysql_close($con);
?>

HTML:

<html>
<meta charset="utf-8">
<head>
    <title>Controla</title>
    <link rel="stylesheet" type="text/css" href="estilologin.css">
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Fjalla+One" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Raleway" rel="stylesheet">
</head>
<body>

<div class="small"></div>

<div class="medium"></div>

<div class="large"></div>

<header id="cabecalhologin">
<div class="interfacelogin">
<img id="Logo" src="imagens/controla.png" style="width:350px; height:355px; margin-left: 51%;">
</div>
</header>
<div class="menulogin">
    <ul>
        <li><a href="index.php">Página Inicial</a></li>
        <li><a href="login.php">Login</a></li>
        <li><a href="Cadastro.php">Cadastrar</a></li>
        <li><a href="#">Minha Conta</a></li>
    </ul>
</div>

<div style="z-index: 99999; top: 4em;">
<h1 style="font-family: 'Lobster'; margin-right: 100px; font-size: 20pt;" id="login">LOGIN</h1>
</div>
<style type="text/css">
    #login {
        position: absolute;
        margin-top: -3em;       
        padding-left: 23.7em;
    }
</style>

<form action="logando.php" method="POST">
<section>
<label style="font-family: 'Fjalla One'; color: #FFFFFF;">Email</label><br>
<input type="text" name="emaillogin"><br>
<label style="font-family: 'Fjalla One'; color: #FFFFFF;">Senha</label><br>
<input type="password" name="senhalogin"><br><br>
<button type="submit">ENTRAR</button>
</section>
</form>

<footer id="sobrelogin">
<p> &copy; Controla Estoque 2018</p>
<h5 style="margin-left: -7.9em;position: relative;"> Um sistema de controle de estoque adequável para comercio de pequenas e microempresas, sendo padaria, pet shop, papelaria entre outros comércios existentes.</h5>
</footer>
</body>
</html>

1 answer

-1


You probably got confused mysql_ with mysqli_. The first error presented in the question is because you reversed the variables in mysql_query($con,$sql);, when the right thing is:

mysql_query($sql, $con);

/* ou */

mysql_query($sql);

The second error you are calling a constant that does not exist, this you because you forgot to add the dollar sign $ before the variable name in if(linha > 0), when the right thing is:

if($linha > 0)

Browser other questions tagged

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