Ver Mensaje Individual
  #7 (permalink)  
Antiguo 17/02/2010, 20:09
QuirogaXD
 
Fecha de Ingreso: febrero-2010
Mensajes: 11
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Login PHP MySQL

Muchas gracias a todos por las respuestas y pido perdón por no haber posteado en el foro adecuado, pensé que lo estaba haciendo correctamente. Siento las molestias

He estado mirando los códigos que me has pasado, DaChux, y la verdad es que me interesaría utilizar AJAX porque el proyecto que estoy haciendo es para clase y seguro que lo valoran mucho, el problema es que no he hecho nada con AJAX y no se exactamente como incluir eso a mi código (está claro que soy un poco negado todavía para esto del PHP...).

Death_Empire, he hecho cambios en el código y creo que ahora las consultas si deberían estar bien, incluso el código debería ser el correcto para poder loguearse, pero siempre me sale "Nombre de usuario o contraseña incorrectos".

Os pongo el código y os indico los cambios que he hecho con respecto al anterior:

Cita:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Informacion sobre Skate Nacional e Internacional</title>
</head>

<body bgcolor="#000000">

<table width="100%" height="80%">
<tr>
<td valign="middle">
<div align="center"><img src="Fotos/LogoInicio2.jpg" /></div>
</td>
</tr>

<tr>
<td> //ESTOS 2 INPUT LOS TENIA FUERA DE UN FORM
<div align="center">
<form action="index.php" method="post">
<font color="white">User: <input type="text" name="uss" value=""><hr width="20%"> Pass: <input type="password" name="pss" value=""/></font>
</form>
</div>
</td>
</tr>
</table>

<table align="center" cellpadding="12">
<tr>
<td>
<form action="index.php" method="post">
<font color="white"><input type="submit" name="conectar" value="Conectar" /></font>
</form>
</td>
<td>
<form action="index.php" method="post">
<font color="white"><input type="submit" name="Nuevo" value="Alta usuario" /></font>
</form>
</td>
</tr>
</table>

<?php
if ($_REQUEST['conectar']=="Conectar")
{
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("proyecto", $con);

//CAMBIO EN LA CONSULTA Y EN LA CONDICIÓN

$nombre = $_POST["uss"];
$password = $_POST["pss"];

$registros = mysql_query("Select Nombre from usuarios where Nombre = '".$nombre."' and Password = '".$password."'");

if (mysql_num_rows($registros) == 0)
{
echo "Nombre de usuario o contraseña incorrectos";
}
else
{
echo "Nombre y contraseña correctos!";
}
mysql_close($con);
}
elseif ($_REQUEST['Nuevo']=='Alta usuario')
{
echo<<<fin
<font color="#FFFFFF">
<br><center> ALTA DE USUARIO. INTRODUZCA USUARIO Y PASSWORD </center><br>
<table width="100%" height="100%">
<tr>
<td valign="middle">
<div align="center">
<form action="index.php" method="post">
User: <input type="text" name="nom" value="" />
<br />
Pass: <input type="password" name="pass" value="" />
<br />
<input type="submit" name="enviar" value="Aceptar" />
</form>
</div>
</td>
</tr>
</table>
</font>
fin;

if ($_REQUEST['enviar']=="Aceptar")
{
$con = mysql_connect("localhost","root","");

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("Proyecto", $con);

$U = $_REQUEST["nom"];
$P2 = $_REQUEST["pass"];

if ($U == NULL && $P2 == NULL)
{
echo "Introduce todos los datos";
}
else
{
mysql_query("INSERT INTO usuarios (Nombre, Password) VALUES ('$_REQUEST[nom]', '$_REQUEST[pass]')");

mysql_close($con);
}
}

}
?>

</body>

</html>
Muchas gracias a todos!!