Error when selecting multiple data in php login

Asked

Viewed 134 times

3

I have a script simple that makes a user of mine website can view your data on a page, for example: name, email, age, image. See script down below:

<html>
<head>
<title> Login de Usuário </title>
</head>
<body>
<form method="POST" action="login.php">
<label>pnome:</label><input type="text" name="pnome" id="pnome"><br>
<label>nomec:</label><input type="text" name="nomec" id="nomec"><br>
<input type="submit" value="entrar" id="entrar" name="entrar"><br>
<a href="cadastro.html">Cadastre-se</a>
</form>
</body>
</html>

This is the PHP that makes the login:

<?php 
$login = $_POST['pnome'];
$entrar = $_POST['entrar'];
$senha = md5($_POST['nomec']);
$connect = mysql_connect('localhost','root','123');
$db = mysql_select_db('banco_cliente');
    if (isset($entrar)) {

        $verifica = mysql_query("SELECT * FROM jogo WHERE pnome = '$pnome' AND nomec = '$nomec'") or die("erro ao selecionar");
            if (mysql_num_rows($verifica)<=0){
                echo"<script language='javascript' type='text/javascript'>alert('Login e/ou senha incorretos');window.location.href='login.html';</script>";
                die();
            }else{
                setcookie("pnome",$pnome);
                header("Location:Pasta/comeng2.php");
                }
    }
?>

This is the page that will show the data of login if he logged on:

<?php
$pnome_cookie = $_COOKIE['pnome'];
    if(isset($pnome_cookie)){
        echo"Bem-Vindo, $pnome_cookie <br>";
        echo" $nomec_cookie <br>";
        echo" $img_cookie <br>";
        echo" $email_cookie <br>";
        echo" $idade_cookie <br>";
        echo"Essas informações <font color='red'>PODEM</font> ser  acessadas por você";
    }else{
        echo"Bem-Vindo, convidado <br>";
        echo"Essas informações <font color='red'>NÃO PODEM</font> ser acessadas por você";
        echo"<br><a href='login.html'>Faça Login</a> Para ler o conteúdo";
    }
?>

Then only returns me the welcome information: "So-and-so this information can be accessed by you!" But the others does not show:

These do not show in the echo:

nomec
img
email
idade

I tried to change the select from the example table:

$verifica = mysql_query("SELECT * FROM jogo WHERE pnome = '$pnome' AND nomec = '$nomec' AND img = '$img' AND email = '$email' AND idade = '$idade'") or die("erro ao selecionar");

But gives error. How to do not give error and return all user data?

  • Where do they come from $pnome and $nomec?

  • of a form in html, which is used to log in has no password.

  • Add the form code to your question, the names may be wrong

  • 1

    please add the error message

  • no error message only is not returning me this data: name img email age

1 answer

2

You have captured the keyword and keyword in $login and $password, try switching to these variables instead.

  • but pnome shows what does not show is the other example data name, img, email, age, I think this is in mysql select.

  • 1

    then, see ($login = $_POST['pnome'];) you transformed what comes from the form with POST into the variable $login, but in the select put like this ($pnome). Confirm that your HTML form has method="POST".

  • checked and yes mu dei and gave error syntax error. prayer that has to use the name login in same name and password in nomec

  • see if I use it like this ($login = $_POST['pnome'];) and select ($pnome) works well for me, but if I do so ($pnome = $_POST['pnome'];) and select ($pnome) from the error. and how to make other options be shown. In the login you only have the option of name and name.

  • 1

    Post the HTML of your form please.

  • ready put the html for you guys take a look.

  • 1

    So Adailton, the other information is in the bank in the table cited? If you specify them in the Select clause, in place of the asterisk, separated by comma and captures them after selecting with mysql_fetch_row, according to the example of the PHP documentation [link]http://php.net/manual/en/function.mysql-fetch-row.php[link].

  • Yes it is on the table yes, ata I thought it was simpler, but there is a little example to give a little help?

Show 3 more comments

Browser other questions tagged

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