Ver Mensaje Individual
  #15 (permalink)  
Antiguo 13/04/2009, 15:25
nestoroc
 
Fecha de Ingreso: marzo-2009
Mensajes: 20
Antigüedad: 15 años, 11 meses
Puntos: 0
Respuesta: como hago que mi PHP para que vea el codigo en la misma pag.?

Intenta esto pero mira bien el código para que lo entiendas.


index2.php
Código PHP:
<?php
session_start
();
//datos para establecer la conexion con la base de mysql.
mysql_connect('233.33.93.154','fontaine_fff','aaa' )or die ('Ha fallado la conexión: '.mysql_error());
mysql_select_db('fontaine_lafontane')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
function 
quitar($mensaje)
{
    
$nopermitidos = array("'",'\\','<','>',"\"");
    
$mensaje str_replace($nopermitidos""$mensaje);
    return 
$mensaje;
}
if(isset(
$_POST["login"]))
{
    if(
trim($HTTP_POST_VARS["usuario"]) != "" && trim($HTTP_POST_VARS["clave"]) != "")
    {
        
// Puedes utilizar la funcion para eliminar algun caracter en especifico
        //$usuario = strtolower(quitar($HTTP_POST_VARS["usuario"]));
        //$password = $HTTP_POST_VARS["password"];
        // o puedes convertir los a su entidad HTML aplicable con htmlentities
        
$usuario strtolower(htmlentities($HTTP_POST_VARS["usuario"], ENT_QUOTES));
        
$clave $HTTP_POST_VARS["clave"];
        
$result mysql_query('SELECT clave, usuario FROM clientes WHERE usuario=\''.$usuario.'\'');
        if(
$row mysql_fetch_array($result))
        {
            if(
$row["clave"] == $clave)
            {
                
$_SESSION["k_username"] = $row['usuario'];
                                
                
header ("Location: index.php"); //Si el ingreso fue exitoso se redirigirá al index.php
                
                // Si quieres que cuando ingresen se dirijan a otra página
                // header ("Location: pagina_entro_con_éxito.php");
            
}
            else
            {
                
header ("Location: index2.php?msj=1");
            }
        }
        else
        {
            
header ("Location: index2.php?msj=2");
        }
    }
    else
    {
        
header ("Location: index2.php?msj=3");
    }
}
mysql_close();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

</head>
<body>
<div>
<?php 
if(isset($_GET['msj']))
{
    
$mensaje_error $_GET['msj'];
    
    if(
$mensaje_error == 1)
    {
        echo 
'clave incorrecta';
    }
    if(
$mensaje_error == 2)
    {
        echo 
'Usuario no existente en la base de datos';
    }
    if(
$mensaje_error == 3)
    {
        echo 
'Debe especificar un usuario y password';
    }
}
?>
</div>


<form action="" method="post">
Usuario:<input type="text" name="usuario" size="20" maxlength="20" />
<br />
Password:<input type="clave" name="clave" size="10" maxlength="10" />
<br />
<input type="submit" name="login" value="Ingresar" />
</form>
</body>
</html>