Foros del Web » Programando para Internet » PHP »

Necesito ayuda con este codigo

Estas en el tema de Necesito ayuda con este codigo en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 21/02/2010, 14:26
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 9 años, 10 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>';
	
}
?>
  #2 (permalink)  
Antiguo 21/02/2010, 14:27
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 9 años, 10 meses
Puntos: 1
Respuesta: Necesito ayuda con este codigo

Aqui la otra parte


Código:
<!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>A Cool Login System With PHP MySQL &amp jQuery | Tutorialzine demo</title>
    
    <link rel="stylesheet" type="text/css" href="demo.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="login_panel/css/slide.css" media="screen" />
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    
    <!-- PNG FIX for IE6 -->
    <!-- http://24ways.org/2007/supersleight-transparent-png-in-ie6 -->
    <!--[if lte IE 6]>
        <script type="text/javascript" src="login_panel/js/pngfix/supersleight-min.js"></script>
    <![endif]-->
    
    <script src="login_panel/js/slide.js" type="text/javascript"></script>
    
    <?php echo $script; ?>
</head>

<body>

<!-- Panel -->
<div id="toppanel">
	<div id="panel">
		<div class="content clearfix">            
            <?php
			
			if(!$_SESSION['id']):
			
			?>
            
			<div class="left">
				<!-- Login Form -->
				<form class="clearfix" action="" method="post">
					<h1>Member Login</h1>
                    
                    <?php
						
						if($_SESSION['msg']['login-err'])
						{
							echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>';
							unset($_SESSION['msg']['login-err']);
						}
					?>
					
					<label class="grey" for="username">Login ID:</label>
					<input class="field" type="text" name="username" id="username" value="" size="23" />
					<label class="grey" for="password">Password:</label>
					<input class="field" type="password" name="password" id="password" size="23" />
	            	<label><input name="rememberMe" id="rememberMe" type="checkbox" checked="checked" value="1" /> &nbsp;Remember me</label>
        			<div class="clear"></div>
					<input type="submit" name="submit" value="Login" class="bt_login" />
				</form>
			</div>
			<form action="" method="post">
			<div class="left right">			
				<!-- Register Form -->				
					<h1>Not a member yet? Sign Up!</h1>		
                    
                    <?php
						
						if($_SESSION['msg']['reg-err'])
						{
							echo '<div class="err">'.$_SESSION['msg']['reg-err'].'</div>';
							unset($_SESSION['msg']['reg-err']);
						}
						
						if($_SESSION['msg']['reg-success'])
						{
							echo '<div class="success">'.$_SESSION['msg']['reg-success'].'</div>';
							unset($_SESSION['msg']['reg-success']);
						}
					?>
                    		
					<label class="grey" for="firstname">First Name/Company Name:</label>
					<input class="field" type="text" name="firstname" id="firstname" value="" size="23" />
					<label class="grey" for="lastname">Last Name/Company Short Name:</label>
					<input class="field" type="text" name="lastname" id="lastname" value="" size="23" />
					<label class="grey" for="username">Login ID:</label>
					<input class="field" type="text" name="username" id="username" value="" size="23" />
					<label class="grey" for="password">Password:</label>
					<input class="field" type="password" name="password" id="password" value="" size="23" />									
			</div>
            <div class="left">
				<label>&nbsp;</label>	
				<label>&nbsp;</label>						
				<label class="grey" for="repassword">Retype Password:</label>
				<input class="field" type="password" name="repassword" id="repassword" value="" size="23" />
					<label class="grey" for="type">Type:</label><select name="type" id="type" style="background-color:#666666; color:#CCCCCC; border-color:#000000; border-style:solid; border-width:thin">
						<option value="Applicant">Applicant</option>
						<option value="Company">Company</option>						
					</select>
					<label class="grey" for="email">Email:</label>
					<input class="field" type="text" name="email" id="email" size="23" />
					<label>Your login data will be e-mailed to you.</label>
					<input type="submit" name="submit" value="Register" class="bt_register" />
				</form>
			</div>			
            <?php
				else:			
			?>
            
            <div class="left">                       
            <p>&nbsp;</p><br /><br /><br /><br /><p>&nbsp;</p><br /><br /><br /><br /><p>&nbsp;</p><br /><br />
            <a href="?logoff"><strong>Log out</strong></a>
            
            </div>
			 <?php
				endif;
			?>               
		</div>
	</div> <!-- /login -->	

    <!-- The tab on top -->	
	<div class="tab">
		<ul class="login">
	    	<li class="left">&nbsp;</li>
	        <li>Hello 
				<?php
					if($_SESSION['id'])
						{echo $_SESSION['username'];}
					else echo 'Guest';
				?>
			!</li>
			<li class="sep">|</li>
			<li id="toggle">
				<a id="open" class="open" href="#"><?php echo $_SESSION['id']?'Open Panel':'Log In | Register';?></a>

				<a id="close" style="display: none;" class="close" href="#">Close Panel</a>			
			</li>
	    	<li class="right">&nbsp;</li>
		</ul> 
	</div> <!-- / top -->
	
</div> <!--panel -->

	  <?php
		if(isset($_SESSION['id']))
			{
				// If you are logged in.
				include("add_applicant.php");					
			}
		?>	     

</body>
</html>
<?php
	ob_flush();
?>

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:15.