php - Error in login Form -


when try log in appear: "el usuario o contraseña es incorrecto", dont know problem. think have done bad when tipping code.

here leave code:

acceso.php

<?php session_start(); $titulo = "acceso al panel"; include 'inc/header.php'; if($_session['logueado'] == true) {     header('location: funciones/panel.php'); }else{ ?> <html> <center> <form method="post" action="funciones/panel.php">   <div class="form-group"> nombre: <input type="text" name="nombre"></input> <hr> contraseña: <input type="password" name="pass"></input> <hr> <input type="submit" name="enviar" value="acceso"></input> </div> </form> </center> </html> <?php include 'inc/footer.php'; } ?> 

the next step: panel.php

<?php session_start(); include 'inc/header.php'; include 'panel_funciones.php';  $usuario = $_post["nombre"]; $pass = $_post["pass"]; try {     $bd = new pdo("mysql:host=localhost;dbname=b9_16267033_1","b9_16267033","123456");     $bd->query("set names 'utf8'"); } catch (exception $e){     echo "no se ha podido conectar";     exit; } try{         $sql= "select usuario, pass usuarios usuario='$usuario' , pass='$pass'"; }catch(exception $e){     echo "error en consulta";     exit; } $iniciosesion=mysql_query($sql); $contar = mysql_num_rows($iniciosesion);  // aqui comienza comprobaciÓn  if ($contar == 1) {     $_session['logueado'] = true; panel(); } else{     echo "el usuario o contraseña es incorrecto"; } include 'inc/footer.php'; ?> 

the function: panel_funciones.php

<? $user = "javier"; function panel(){ session_start(); echo "<center><h3>bienvenido al panel de control</h1></center></h3></center>";    echo '<form action="logout.php" method="post">';    echo '<input type="submit" value="salir"></form>';    echo '<center> <h4>añadir imagen</h4><hr> <form method="post" action="accion.php"> <div class="form-group"> nombre: <input type="text" name="titulo"></input> link imagen: <input type="text" name="link"></input> <input type="submit" name="enviar" value="enviar"></input> </div> </form> <center>'; echo ' <h4>eliminar imagen</h4><hr> <form method="post" action="accion2.php"> escribe link <input type="text" name="imagen"></input> <input type="submit" name="enviar2" value="enviar"></input>'; } ?> 

thanks help, im trying learn time time need ask questions.

great job using pdo.

but assume u forgot check paremeters take mysql_query : u're using pdostatement instead of string.

panel.php

... $sql=$bd->query("select usuario, pass                   usuarios                   usuario='$usuario' , pass='$pass') "); } catch(exception $e){ echo "error en consulta"; exit; } // continue use pdo instead depreciated functions :'( // using fetchall() & count instead  $iniciosesion=mysql_query($sql); $contar = mysql_num_rows($iniciosesion); 

.move these 2 last lines last try & replace them :

$iniciosesion = $bd->query($sql); $result = $iniciosesion->fetchall(); $contar = count($result); 

acceso.php

u missed <html> tags in ur main page.

<?php session_start(); ?> <html> <head></head> <body> <?php  ... //then close body & html close @ end of file. 

source :

php.net : pdostatement::fetchall

php.net mysql_query


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -