Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/02/2010, 14:26
den_22
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Necesito ayuda con este codigo

Hola!, que tal necesito ayuda con este codigo urgente, estoy hace unas cuantas horas viendo cual es el problema y no lo encuentro. La cuestion es asi, un sistema de login+registro,que muestra errores, al presionar en register, si todo está bien el mensaje es "We sent you an email with your login data!", pero el tema es que no hace la insercion a la bd; y en cambio dice "This username has already taken."
Hice la consulta a la bd pero se inserta haciendo esto. Asi que no le encuentro la respuesta a este problema.

Si alguien me puede ayudar le agradeceria.

Aca el codigo de la bd:

Código:
CREATE TABLE `tz_members` (
  `id` int(11) NOT NULL auto_increment,
  `usr` varchar(32) collate utf8_unicode_ci NOT NULL default '',
  `pass` varchar(32) collate utf8_unicode_ci NOT NULL default '',
`firstname` varchar(32) collate utf8_unicode_ci NOT NULL default '',
`lastname` varchar(32) collate utf8_unicode_ci NOT NULL default '',
`type` varchar (32) collate utf8_unicode_ci NOT NULL default '',
  `email` varchar(255) collate utf8_unicode_ci NOT NULL default '',
  `regIP` varchar(15) collate utf8_unicode_ci NOT NULL default '',
  `dt` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`),
  UNIQUE KEY `usr` (`usr`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Aca el codigo del index:

Código:
<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();

define('INCLUDE_CHECK',true);

require 'connect.php';
require 'functions.php';
// Those two files can be included only if INCLUDE_CHECK is defined


session_name('tzLogin');
// Starting the session

session_set_cookie_params(2*7*24*60*60);
// Making the cookie live for 2 weeks

session_start();

if($_SESSION['id'] && !isset($_COOKIE['tzRemember']) && !$_SESSION['rememberMe'])
{
	// If you are logged in, but you don't have the allnurseRemember cookie (browser restart)
	// and you have not checked the rememberMe checkbox:

	$_SESSION = array();
	session_destroy();
	
	// Destroy the session
}


if(isset($_GET['logoff']))
{
	$_SESSION = array();
	session_destroy();
	
	header("Location: demo.php");
	exit;
}

if($_POST['submit']=='Login')
{
	// Checking whether the Login form has been submitted
	
	$err = array();
	// Will hold our errors
	
	
	if(!$_POST['username'] || !$_POST['password'])
		$err[] = 'All the fields must be filled in!';
	
	if(!count($err))
	{
		$_POST['username'] = mysql_real_escape_string($_POST['username']);
		$_POST['password'] = mysql_real_escape_string($_POST['password']);
		$_POST['rememberMe'] = (int)$_POST['rememberMe'];
		
		// Escaping all input data
		
		$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM tz_members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));
						
		if($row['usr']) 
		{
			// If everything is OK login
			
			//$_SESSION['username']=$row['user'];
			$_SESSION['usr']=$row['usr'];
			$_SESSION['id'] = $row['id'];
			$_SESSION['type'] = $row['type'];
			$_SESSION['rememberMe'] = $_POST['rememberMe'];
			
			// Store some data in the session
			
			setcookie('tzRemember',$_POST['rememberMe']);
		}
		else	$err[]='Wrong username and/or password!';			
	}
	
	if($err)
	$_SESSION['msg']['login-err'] = implode('<br />',$err);
	// Save the error messages in the session

	header("Location: demo.php");
	exit;
}
else if($_POST['submit']=='Register')
{
	// If the Register form has been submitted
	
	$err = array();
	
	if(strlen($_POST['firstname'])>100)
	{
		$err[]='Your lastname must be less 100 characters!';
	}
	
	if(!preg_match('/[^0-9\-\_\.]+/i',$_POST['firstname']))
	{
		$err[]='Your firstname contains invalid characters!';
	}
	
	if(strlen($_POST['lastname'])>100)
	{
		$err[]='Your lastname must be less 100 characters!';
	}
	
	if(!preg_match('/[^0-9\-\_\.]+/i',$_POST['lastname']))
	{
		$err[]='Your lastname contains invalid characters!';
	}
	
	if(strlen($_POST['username'])<4 || strlen($_POST['username'])>100)
	{
		$err[]='Your username must be between 4 and 100 characters!';
	}
	
	if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['username']))
	{
		$err[]='Your username contains invalid characters!';
	}
	
	if(strlen($_POST['password'])<6 || strlen($_POST['password'])>32)
	{
		$err[]='Your password must be between 6 and 32 characters!';
	}
	
	if(preg_match('/[^a-z0-9\-\_\.]+/i',$_POST['password']))
	{
		$err[]='Your password is weak!';
	}
	
	if($_POST['repassword']!=$_POST['password'])
	{
		$err[]='Your retype password is different than password!';
	}
	
	if(!checkEmail($_POST['email']))
	{
		$err[]='Your email is not valid!';
	}
	
	if(!count($err))
	{
		// If there are no errors
		
		$_POST['email'] = mysql_real_escape_string($_POST['email']);
		$_POST['password'] = mysql_real_escape_string($_POST['password']);
		$_POST['username'] = mysql_real_escape_string($_POST['username']);
		$_POST['firstname'] = mysql_real_escape_string($_POST['firstname']);
		$_POST['lastname'] = mysql_real_escape_string($_POST['lastname']);
		$_POST['type'] = mysql_real_escape_string($_POST['type']);
		// Escape the input data
		
		
		mysql_query("	INSERT INTO tz_members(firstname,lastname,usr,pass,email,type,dt)
						VALUES('".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['username']."','".md5($_POST['password'])."','".$_POST['email']."','".$_POST['type']."',NOW())");
								
		
		if(mysql_affected_rows($link)==1)
		{
			send_mail(	'[email protected]',
						$_POST['email'],
						'Registration for Deemo',
						'Your username is: '.$username.'\n Your password is: '.$password);

			$_SESSION['msg']['reg-success']='We sent you an email with your login data!';
		}
		else $err[]='This username is already taken!';
	}

	if(count($err))
	{
		$_SESSION['msg']['reg-err'] = implode('<br />',$err);
	}	
	
	header("Location: demo.php");
	exit;
}

$script = '';

if($_SESSION['msg'])
{
	// The script below shows the sliding panel on page load
	
	$script = '
	<script type="text/javascript">
	
		$(function(){
		
			$("div#panel").show();
			$("#toggle a").toggle();
		});
	
	</script>';
	
}
?>