Hola a todos y feliz navidad! Tengo un problema con un codigo q no me funciona...el problema esta en q cuando el usuario va inisiar sesion...no puede entrar....me sale un error, aqui esta el codigo.
<title><? echo $titulo; ?>-Entrar</title>
<?
include("config.php") ;
if($entrar) {
function quitar($texto) {
$texto = trim($texto) ;
$texto = htmlspecialchars($texto) ;
return $texto ;
}
$nick = quitar($nick) ;
$contrasena = quitar($contrasena) ;
$tema = quitar($tema) ;
$resp = mysql_query("select contrasena,tema from usuarios where nick='$nick'") ;
$datos = mysql_fetch_array($resp) ;
if(mysql_num_rows($resp) != 0) {
if($datos[contrasena] == $contrasena) {
setcookie("npnick",$nick,time()+3600) ;
setcookie("nptema",$tema,time()+3600) ;
header("location: index.php") ;
}
else {
echo "La contraseña es incorrecta. Haz click <a href=javascript:history.back()>aquí</a> para regresar." ;
}
}
else {
echo "Este usuario no existe en la base de datos." ;
}
}
else {
echo "
<form method=post action=index.php?id=entrar>
<b>Nick:</b><br>
<input type=text name=nick maxlength=20 class=form><br>
<b>Contraseña:</b><br>
<input type=password name=contrasena maxlength=20 class=form><br><br>
<input type=submit name=entrar value=Entrar class=form>
</form>
" ;
}
?>
y cual es el error, no somos adivinos.
Así por encima.. ¿La variable $contraseña?
Observaciones,
De donde sale el valor de la variable $entrar?
if($entrar){
-----
Para qué el TRIM(), en la función QUITAR();?
function quitar($texto){
$texto = trim($texto);
$texto = htmlspecialchars($texto);
return $texto ;
}
Si existe un usuario con el nick 'Shell Root', podrá loggearse?
-----
El código más organizado, y creo que deberías de re-estructurar esos campos con caracteres especiales en la base de datos...
<title><?PHP echo $titulo; ?> - sLogin</title>
<?PHP
include( "config.php" );
if( $sLogin ){
function sRemove( $sString ){
$sString = trim( $sString );
$sString = htmlspecialchars( $sString );
return $sString;
}
$sNick = sRemove( $sNick );
$sPassword = sRemove( $sPassword );
$sTopic = sRemove( $sTopic );
$sSQL = "SELECT Password, Topic FROM tblUsers WHERE nick = '".$sNick."'";
$sQuery = mysql_query( $sSQL );
$sFetchRows = mysql_fetch_array( $sQuery );
if( mysql_num_rows( $sQuery ) != 0 ){
if( $sFetchRows['Password'] == $sPassword ){
setcookie( "npnick", $sNick, time() + 3600 );
setcookie( "nptopic", $sTopic, time() + 3600) ;
header( "location: index.php" );
}else{
echo "La Password es incorrecta. Haz click <a href = 'javascript:history.back()'>aquí</a> para regresar.";
}
}else{
echo "Este usuario no existe en la base de datos.";
}
}else{
echo "<form method='POST' action='index.php?id=sLogin'>
<b>Nick:</b><br>
<input type='text' name='nick' maxlength='20' class='form'><br>
<b>Password:</b><br>
<input type = 'password' name = 'Password' maxlength = '20' class = 'form'><br><br>
<input type = 'submit' name = 'Login' value = 'Login' class = 'form'>
</form>";
}
?>
Gracias! voy aver si me funciona....
Cita de: Shell Root en 22 Diciembre 2010, 16:47 PM
Para qué el TRIM(), en la función QUITAR();?
function quitar($texto){
$texto = trim($texto);
$texto = htmlspecialchars($texto);
return $texto ;
}
Si existe un usuario con el nick 'Shell Root', podrá loggearse?
La verdad es que sí que podrá, creo que el trim() ahí no está de más.
Citar
string trim ( string $str [, string $charlist ] )
Esta función devuelve una cadena con los espacios en blanco eliminados del inicio y final del str. sin el segundo parámetro, trim() eliminará estos caracteres:
" " (ASCII 32 (0x20)), espacio simple.
"\t" (ASCII 9 (0x09)), tabulación.
"\n" (ASCII 10 (0x0A)), salto de línea.
"\r" (ASCII 13 (0x0D)), retorno de carro.
"\0" (ASCII 0 (0x00)), el byte NUL.
"\x0B" (ASCII 11 (0x0B)), tabulación vertical.
http://php.net/manual/es/function.trim.php
trim() borra los espacios al principio y final de la cadena, pero no los que están entre dos palabras.
:o eso no lo sabía...
si vale, igual que en vb
Shell Root Tengo una pregunta como hago esto:
Citarcreo que deberías de re-estructurar esos campos con caracteres especiales en la base de datos...
Por q creo q el error esta en la base de datos...x q el codigo esta bien! :)
hola, Nesesito ayuda con este codigo q no me funciona:...
<title><? echo $titulo ?>-Enviar Boletin</title>
<?php
if (isset ($enviar)) {
if($enviar) {
function quitar($texto) {
$texto = trim($texto) ;
$texto = htmlspecialchars($texto) ;
return $texto ;
}
$fecha = time() - 25200 ;
$mensaje = quitar($mensaje) ;
include ("conexion.php");
$resp = mysql_query ("SELECT nick FROM usuarios where boletin='si'",$conexion);
while ($row = mysql_fetch_array ($resp)) {
$nick = $row ["nick"];
$mensaje = $_POST ["mensaje"];
}
}
else {
$remitente =Boletin ;
mysql_query("insert into mensajes (fecha,destinatario,remitente,asunto,mensaje) values ('$fecha','$nick','$remitente','Boletin','$mensaje')") ;
echo "<p>El Boletin ha sido enviado con éxito. Haz click <a href=index.php>aquí</a> para regresar." ;
}
}
else {
?>
<form action="<?php $PHP_SELF ?>" method="post">
Introduce el mensaje:<br><br>
<textarea name="mensaje" cols=30 rows=5 class="form"></textarea>
<br><br>
<input type="submit" name="enviar" value="Enviar Boletin" class="form">
</form>
<?php
}
?>
<title><? echo $titulo; ?>-Enviar Boletin</title>
<?php
if (isset ( $enviar )){
if( $enviar ){
function quitar( $texto ){
$texto = trim( $texto );
$texto = htmlspecialchars( $texto );
return $texto;
}
$fecha = time() - 25200;
$mensaje = quitar( $mensaje );
include ( 'conexion.php' );
$resp = mysql_query ( "SELECT nick FROM usuarios WHERE boletin='si'", $conexion );
while ($row = mysql_fetch_array ($resp)) {
$nick = $row ['nick'];
$mensaje = $_POST ['mensaje'];
}
}else{
$remitente = Boletin;
mysql_query( "INSERT INTO mensajes (fecha, destinatario, remitente, asunto, mensaje) VALUES ('". $fecha ."', '". $nick ."', '". $remitente. "', '". Boletin. "', '". $mensaje ."')" );
echo "<p>El Boletin ha sido enviado con éxito. Haz click <a href='index.php'>aquí</a> para regresar.";
}
}else{
?>
<form action='<?php $PHP_SELF; ?>' method='POST'>
Introduce el mensaje:<br><br>
<textarea name='mensaje' cols='30' rows='5' class='form'></textarea>
<br><br>
<input type='submit' name='enviar' value='Enviar Boletin' class='form'>
</form>
<?php
}
?>
1000 gracias Shell Root...