Autor
|
Tema: Como hago con este codigo? (Leído 3,764 veces)
|
den_22
Desconectado
Mensajes: 69
|
Hola, tengo una pregunta acerca de este código, la cuestion es que al querer hacer el registro siempre en el formulario, me dice "This username has already taken",ademas si no se registra en la bd, como ya va a estar siendo usado?. Dejo el código a ver si me pueden dar una mano.(La parte en negrita calculo que debe estar provocando esto) <?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 username 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,user,password,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( 'name@yourdomain.com', $_POST['email'], 'Registration for Demo', '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>'; } ?>
|
|
« Última modificación: 22 Febrero 2010, 17:32 pm por den_22 »
|
En línea
|
|
|
|
Alex_bro
Desconectado
Mensajes: 1.246
|
No me he detenido mucho a leer el codigo, porque ando escasito de tiempo hoy por los examenes jaja, pero he visto que ese mensaje salta cuando no es capaz de hacer el insert en la DB... Seguro que ha conextado bien a la db, existe la tabla, y demas? Prueba a intentar ejecutar la misma query desde phpmyadmin (por ejemplo) a ver si te dice cual es el error que tira mysql.
Saludos.
|
|
|
En línea
|
|
|
|
den_22
Desconectado
Mensajes: 69
|
Bueno gracias, lo pruebo y te digo.
den_22
|
|
|
En línea
|
|
|
|
luiggy2
Desconectado
Mensajes: 439
¡ Hello word ! XD
|
Hola, tengo una pregunta acerca de este código, la cuestion es que al querer hacer el registro siempre en el formulario, me dice "This username has already taken",ademas si no se registra en la bd, como ya va a estar siendo usado?. Dejo el código a ver si me pueden dar una mano.(La parte en negrita calculo que debe estar provocando esto) <?php require 'connect.php'; require 'functions.php'; // Those two files can be included only if INCLUDE_CHECK is defined // Starting the session // Making the cookie live for 2 weeks 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: // Destroy the session } if(isset($_GET['logoff'])) { } if($_POST['submit']=='Login') { // Checking whether the Login form has been submitted // Will hold our errors if(!$_POST['username'] || !$_POST['password']) $err[] = 'All the fields must be filled in!'; { $_POST['rememberMe'] = (int)$_POST['rememberMe']; // Escaping all input data 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 } else if($_POST['submit']=='Register') { // If the Register form has been submitted 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 username 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 there are no errors // Escape the input data mysql_query(" INSERT INTO tz_members(firstname,lastname,user,password,email,type,dt) VALUES('".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['username']."','".md5($_POST['password'])."','".$_POST['email']."','".$_POST['type']."',NOW())"); { send_mail( 'name@yourdomain.com', $_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!'; } { $_SESSION['msg']['reg-err'] = implode('<br />',$err); } } $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>'; } ?>
Mejor asi ¿No?
|
|
|
En línea
|
" Las grandes ideas suelen salir la mayoría de veces de grandes estupideces "
|
|
|
den_22
Desconectado
Mensajes: 69
|
Hola dejo la tabla de la base de datos, por si alguien me quiere dar una mano, no le encuentro el error. 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;
|
|
|
En línea
|
|
|
|
den_22
Desconectado
Mensajes: 69
|
Ya pude solucionar el problema.
|
|
|
En línea
|
|
|
|
den_22
Desconectado
Mensajes: 69
|
Hola nuevamente, tengo un pequeño problema otra vez, la verdad es que lo habia solucionado, pero no se que pasó, tengo el mismo error otra vez. "This username is already taken". Alguien me podrá ayudar? <?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 username 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,user,password,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( 'name@yourdomain.com', $_POST['email'], 'Registration for Demo', '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>'; } ?>
<html> <head> </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" /> 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> </label> <label> </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> </p><br /><br /><br /><br /><p> </p><br /><br /><br /><br /><p> </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"> </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"> </li> </ul> </div> <!-- / top --> <div> <!--panel --></div>
<?php if(isset($_SESSION['id'])) { // If you are logged in. include("registered.php"); } ?> </body> </html>
|
|
|
En línea
|
|
|
|
den_22
Desconectado
Mensajes: 69
|
Encontré la solución, el problema era que al crear la base de datos en el phpMyAdmin, debía ponerle en "Cotejamiento" utf8_unicode_ci. Cosa que no estaba puesto. Ahora funciona perfecto!
|
|
|
En línea
|
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
como hago la busqueda por el nombre el codigo lo hace x el salario
Programación C/C++
|
vicrud
|
1
|
2,058
|
23 Abril 2011, 19:11 pm
por Slava_TZD
|
|
|
Como hacer compatible este codigo y FitText con IE6-9
Desarrollo Web
|
z3nth10n
|
0
|
1,802
|
11 Enero 2013, 20:13 pm
por z3nth10n
|
|
|
¿Como sustituyo este codigo por otro para que no salte el AV?
« 1 2 »
Programación Visual Basic
|
xivan25
|
12
|
6,500
|
1 Abril 2013, 15:46 pm
por raul338
|
|
|
Que hago para que Windows no detenga este dispositivo(Código 43)
Windows
|
Saigo79
|
0
|
2,369
|
16 Marzo 2015, 16:08 pm
por Saigo79
|
|
|
Como hago para loguearme en el movil si se me ha olvidado el codigo de desbloque
Dudas Generales
|
win_7
|
8
|
4,656
|
24 Julio 2020, 18:25 pm
por win_7
|
|