Hola buenas noches/ días.
Tengo el siguiente código que debería chequear al usuario que entra por su usuario y contraseña y posteriormente re-dirigirlo a otra página, donde debería mostrar todos los registros de este usuario (correspondientes a su email) que se encuentran en una BD.
Alguna sugerencia o código mejorado.
mi código de verificación es:
Código PHP:
Ver original<?php require_once('../../Connections/contactos.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
}
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ?
intval($theValue) : "NULL"; break;
case "double":
$theValue = ($theValue != "") ?
doubleval($theValue) : "NULL"; break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$query_Recordset1 = "SELECT * FROM contactos";
?>
<?php
// *** Validate request to login to this site.
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) { $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['textfield'])) { $loginUsername=$_POST['textfield'];
$password=$_POST['textfield2'];
$loginUsername2=$_POST['textfield3'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "modificar.php";
$MM_redirectLoginFailed = "acceso no permitido.php";
$MM_redirecttoReferrer = false;
$LoginRS__query=sprintf("SELECT nombre_usuario, password, mailcontacto FROM contactos WHERE nombre_usuario=%s AND password=%s AND mailcontacto=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"), GetSQLValueString($loginUsername2, "hidden"));
if ($loginFoundUser) {
$loginStrGroup = "";
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
$_SESSION['MM_Username'] = $loginUsername;
if (isset($_SESSION['PrevUrl']) && false) { $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess ); }
else {
header("Location: ". $MM_redirectLoginFailed ); }
}
?><style type="text/css">
<!--
body {
background-color: WHITE;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
-->
</style>
<div align="center">
<table width="78%" border="0">
<tr>
<td height="120"><div align="center">
<table width="100%" border="0" cellspacing="0">
<tr>
<td height="0" bgcolor="WHITE"><div align="center">___ </div></td>
</tr>
<tr>
<td height="52" bgcolor="WHITE"><div align="center">
<table width="60%" border="0">
<tr>
<td bgcolor="WHITE"><div align="center"><strong style="font-size: xx-large; color: #000;">Talla variada</strong></div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td height="17" bgcolor="WHITE"> </td>
</tr>
<tr>
<td bgcolor="WHITE"><div align="center">
<table width="17%" border="0">
<tr>
<td width="47%"><div align="center"> <img src="http://.../datos internos/fotos/regresar.png" alt="Regresar " width="33" height="35" hspace="10" border="0" align="absmiddle" onclick="history.back(-1);" />Regresar</div></td>
</tr>
</table>
</div></td>
</tr>
</table>
</div></td>
</tr>
<tr>
<td><div align="center">
<table width="100%" border="0">
<tr>
<td height="4" bgcolor="WHITE"> </td>
</tr>
</table>
</div></td>
</tr>
</table>
</div>
<div align="center"></div>
<form name="form1" method="POST" action="<?php echo $loginFormAction; ?>">
<label><br>
</label>
<div align="center">
<table width="43%" border="0">
<tr>
<td height="30" colspan="2" bgcolor="white"><div align="center" style="color: black; font-weight: bold; font-size: large;">Autentificación usuario:</div></td>
</tr>
<tr>
<td width="40%" bgcolor="WHITE"><div align="right" style="color: black">Usuario:</div></td>
<td width="60%" bgcolor="WHITE"><div align="left">
<input type="loginUsername" name="textfield" id="textfield">
</div></td>
</tr>
<tr>
<td bgcolor="WHITE"><div align="right" style="color: black">Contraseña:</div></td>
<td bgcolor="WHITE"><div align="left">
<input type="password" name="textfield2" id="textfield2">
</div></td>
</tr>
<tr>
<td bgcolor="WHITE"> </td>
<td bgcolor="WHITE"><div align="left">
<input name="loginUsername2" type="hidden" id="textfield3" value="modificar.php?idempleado=<?php echo $row_Recordset1['mailcontacto']; ?>" />
</div></td>
</tr>
</table>
<table width="88%" border="0">
<tbody>
<tr>
<td height="55" bgcolor="WHITE"><div align="center"><span style="font-size:small; color:black;">Recuerde la referencia de su pedido.</span></div></td>
</tr>
</tbody>
</table>
<p>
<label>
<input type="submit" name="button" id="button" value="Enviar">
</label>
</p>
</div>
</form>
<div align="center"></div>
<p align="center"><a href="http://..."></a></p>
<div align="center">_ </div>
<p>
<?php
?>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
el código para validar me da error al enviarlo.
Código HTML:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Pretendo que al validar el usuario, se redirija a otra página, donde el usuario pueda visualizar sus artículos contenidos en una BD, para poder modificarlos o eliminarlos.
Muchas gracias