Foros del Web » Programando para Internet » PHP »

Ayuda con este código

Estas en el tema de Ayuda con este código en el foro de PHP en Foros del Web. Hola a todos, tengo un pequeño problema con este código de registro. Cuando lo ejecuto en mi pc, con wamp, me tira el siguiente error: ...
  #1 (permalink)  
Antiguo 21/01/2010, 12:18
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Ayuda con este código

Hola a todos, tengo un pequeño problema con este código de registro. Cuando lo ejecuto en mi pc, con wamp, me tira el siguiente error: "Parse error: parse error in C:\wamp\www\index.php on line 13"

Que puedo hacer?

Código:
<html>

<head>

<title>registro</title>
<?php

if (isset($_POST['submitted'])) {

    $errors = array ();
        require_once ('mysql_connect.php')

if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {

    
    $user= mysql_real_escape_string($_POST['username']);
    $query="SELECT username FROM users WHERE username = '$user'";
    $result=@mysql_query($query);
    $num=@mysql_num_rows($result);
    
    if($num> 0) {
        $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
    } else {
        $username =mysql_real_escape_string($_POST['username']);
    }
  } else {
        $errors[]='<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
        
        }


if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+)
{1,2}', stripslashes(trim($_POST['email'])) )) {
        $errors[]= '<font color="red">Please provide a valid email adress.</font>';
        } else {
            $email=mysql_real_escape_string($_POST['email']);
        
        }

if(!empty($_POST['password1'])) {
    if($_POST['password1'] != $_POST['password2']){
        $errors[]='<font color="red">The 2 passwords you have entered do not match.</font>';
        } else {
            $password=$_POST['password1'];
        }
    } else {
        $errors[]='<font color ="red">Please provide a password.</font>';
    }


if(empty($errors)) {
            $a=md5(uniqid(rand(),true));
        $query="INSERT INTO users (username, email, password, active) VALUES ('$username','$email', SHA('$password'), '$a')";
        
        
        $result= @mysql_query($query);
        
        if(mysql_affected_rows()==1) {
        
                //Send the E-Mail
                
                $body="Thank you for registering at the User Registration Site.To activate your account, please click on this link:\n\n";
                $body.="http://www.whateveraddressyouwantthere.com/activate.php?x=" . mysql_insert_id()"&y=$a";
                
                    mail($_POST['email'], 'Registration Confirmation', $body, 'From:[email protected]');
                    
                    
                        //Show thank message
                
                echo '<h3>Thank You!</h3>
                
                You have been registered, you have been sent an e-mail to the address you specified before.Please check your e-mails to activate your
account. ';
                } else {
                
                    echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';

    }
    ?>

</head>

<body>
<h3>Register</h3>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlenght="30" />
<small>Username</small></p>
<p><input type="password" name="password1" size="30" maxlenght="40" />
<small>Password</small></p>
<p><input type="password" name="password2" size="30" maxlenght="40" />
<small>Confirm Password</small></p>

<p><input type="text" name="email" size="30" maxlenght="30" value="<?php if(isset($_POST['mail'])) { echo $_POST['mail']; } ?>" /> <small> Email Address</small></p>

<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />

</form>

</body>

</html>
  #2 (permalink)  
Antiguo 21/01/2010, 12:21
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: Ayuda con este código

te falta ; en la linea del require_once -.-
  #3 (permalink)  
Antiguo 21/01/2010, 12:21
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Ayuda con este código

En la línea anterior te falta el caracter de fin de instrucción (;), además, el primer bloque if no se cierra en ninguna parte.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #4 (permalink)  
Antiguo 21/01/2010, 21:01
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: Ayuda con este código

Bueno muchas gracias, por contestar. Ahora tengo un pequeño problemita, corregí lo que me faltaba, pero en la ultima linea me tira "Parse error: parse error in C:\wamp\www\1.php on line 101"
Cual es el problema?, este archivo lo guardo con extensión php, pero tiene html dentro.
Aca está el codigo:

Código:
<?php
if (isset($_POST['submitted'])) {

    $errors = array ();
        require_once ('mysql_connect.php');
		}
		
		
		

if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
    
    $user= mysql_real_escape_string($_POST['username']);
    $query="SELECT username FROM users WHERE username = '$user'";
    $result=@mysql_query($query);
    $num=@mysql_num_rows($result);

    
    if($num> 0) {
        $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
    } else {
        $username =mysql_real_escape_string($_POST['username']);
    }
  } else {
        $errors[]='<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
        
        }


if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+)
{1,2}', stripslashes(trim($_POST['email'])) )) {
        $errors[]= '<font color="red">Please provide a valid email adress.</font>';
        } else {
            $email=mysql_real_escape_string($_POST['email']);
        
        }

if(!empty($_POST['password1'])) {
    if($_POST['password1'] != $_POST['password2']){
        $errors[]='<font color="red">The 2 passwords you have entered do not match.</font>';
        } else {
            $password=$_POST['password1'];
        }
    } else {
        $errors[]='<font color ="red">Please provide a password.</font>';
    }


if(empty($errors)) {
            $a=md5(uniqid(rand(),true));
        $query="INSERT INTO users (username, email, password, active) VALUES ('$username','$email', SHA('$password'), '$a')";
        
        
        $result= @mysql_query($query);
        
        if(mysql_affected_rows()==1) {
        
                //Send the E-Mail
                
                $body="Thank you for registering at the User Registration Site.To activate your account, please click on this link:\n\n";
                $body.="http://www.whateveraddressyouwantthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
                
                    mail($_POST['email'], 'Registration Confirmation', $body, 'From:[email protected]');
                    
                    
                        //Show thank message
                
                echo '<h3>Thank You!</h3>
                
                You have been registered, you have been sent an e-mail to the address you specified before.Please check your e-mails to activate your
account. ';
                } else {
                
                    echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';

    }
    ?>

<html>
<head>
</head>
<body>
<h3>Register</h3>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlenght="30" />
<small>Username</small></p>
<p><input type="password" name="password1" size="30" maxlenght="40" />
<small>Password</small></p>
<p><input type="password" name="password2" size="30" maxlenght="40" />
<small>Confirm Password</small></p>

<p><input type="text" name="email" size="30" maxlenght="30" value="<?php if(isset($_POST['mail'])) { echo $_POST['mail']; } ?>" /> <small> Email Address</small></p>

<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />

</form>
</body>
</html>
  #5 (permalink)  
Antiguo 21/01/2010, 21:06
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Ayuda con este código

Este bloque if tampoco se cierra:
Código PHP:
Ver original
  1. if(empty($errors)) {
Revisa bien los mensajes de errores, revisa la línea que te indica, así te será más fácil depurar el código.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #6 (permalink)  
Antiguo 21/01/2010, 21:11
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: Ayuda con este código

Muchas gracias David, ahi me percaté de eso.
  #7 (permalink)  
Antiguo 22/01/2010, 11:08
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: Ayuda con este código

Hola nuevamente, tengo otro problemita con este código me está matando, debe ser una tonteria.

en la linea 59 me tira un error que dice asi : "Warning: mysql_affected_rows() [function.mysql-affected-rows]: A link to the server could not be established in ... on line 59"


Aqui la linea del codigo:

Código:
        57.   $result= @mysql_query($query);
        58.   }
        59.   if(mysql_affected_rows()==1) {

Gracias de antemano
  #8 (permalink)  
Antiguo 22/01/2010, 11:39
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: Ayuda con este código

1- el error dice que no se pudo establecer una conexion, la tienes declarada?

2- no deberias ocultar los errores con la @ :/
  #9 (permalink)  
Antiguo 22/01/2010, 12:17
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Respuesta: Ayuda con este código

Bueno gracias, acá está el codigo

Código:
<?php
if (isset($_POST['submitted'])) {

    $errors = array ();
        require_once ('mysql_connect.php');
		}
		
		
		

if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {
    
    $user= mysql_real_escape_string($_POST['username']);
    $query="SELECT username FROM users WHERE username = '$user'";
    $result=@mysql_query($query);
    $num=@mysql_num_rows($result);
	
	
	
    
    if($num> 0) {
        $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
    } else {
        $username =mysql_real_escape_string($_POST['username']);
    }
  } else {
        $errors[]='<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
        
        }


if (!eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+)
{1,2}', stripslashes(trim($_POST['email'])) )) {
        $errors[]= '<font color="red">Please provide a valid email adress.</font>';
        } else {
            $email=mysql_real_escape_string($_POST['email']);
        
        }

if(!empty($_POST['password1'])) {
    if($_POST['password1'] != $_POST['password2']){
        $errors[]='<font color="red">The 2 passwords you have entered do not match.</font>';
        } else {
            $password=$_POST['password1'];
        }
    } else {
        $errors[]='<font color ="red">Please provide a password.</font>';
    }


if(empty($errors)) {
            $a=md5(uniqid(rand(),true));
        $query="INSERT INTO users (username, email, password, active) VALUES ('$username','$email', SHA('$password'), '$a')";
        
        
        $result= @mysql_query($query);
        }
        if(mysql_affected_rows()==1) {
        
                //Send the E-Mail
                
                $body="Thank you for registering at the User Registration Site.To activate your account, please click on this link:\n\n";
                $body.="http://www.whateveraddressyouwantthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";
                
                    mail($_POST['email'], 'Registration Confirmation', $body, 'From:[email protected]');
                    
                    
                        //Show thank message
                
                echo '<h3>Thank You!</h3>
                
                You have been registered, you have been sent an e-mail to the address you specified before.Please check your e-mails to activate your
account. ';
                } else {
                
                    echo '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';

    }
    

?>
<html>
<head>
</head>
<body>
<h3>Register</h3>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlenght="30" />
<small>Username</small></p>
<p><input type="password" name="password1" size="30" maxlenght="40" />
<small>Password</small></p>
<p><input type="password" name="password2" size="30" maxlenght="40" />
<small>Confirm Password</small></p>

<p><input type="text" name="email" size="30" maxlenght="30" value="<?php if(isset($_POST['mail'])) { echo $_POST['mail']; } ?>" /> <small> Email Address</small></p>

<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />

</form>
</body>
</html>

Ahora bien, el error es en la linea 58 lo que te dije antes. Deberia declararla donde dice :
Código:
    $user= mysql_real_escape_string($_POST['username']);
    $query="SELECT username FROM users WHERE username = '$user'";
    $result=@mysql_query($query);
    $num=@mysql_num_rows($result);

Seria de gran ayuda si me explicas, el tema es que quiero tratar de entenderlo.
Muchas gracias.

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 06:13.