Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Registration form - cant see whats going wrong??

    Hey
    i made a thread the other dayand was helped out alot allthough this is the same php code it is alot diffrent now (added regex, changed the input form and checks to make sure theres no duplicates) and is a diffrent error, so iv made this topic.

    Im not getting an error message but the code is not working. The regex checks is all working fine, getting the datas fine but its not added any records to the database. I cant see why iv commented the code and listed the code for the input, If anyone can spot what iv done wrong itd be greatly appreciated Thanks!!

    Input form
    Code:
    <!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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    <form action="Register2.php" method="post">
    
    <table width="100%" border="0">
    <tr>
        <td width="300">Username ( Min 6 chars ):</td>
    
        <td width="300" > <input type="text" name="username" size="32"> * </td>
    
    </tr>
    <tr>
        <td>Password ( Min 6 chars ):</td>
    
        <td><input type="password" name="password" size="32"> *</td>
    
    </tr>
    <tr>
        <td>Retype Password:</td>
        <td><input type="password" name="password2" size="32"> *</td>
    
    </tr>
    <tr>
        <td>Your Email:</td>
        <td><input type="text" name="email" size="32"> *</td>
    
    </tr>
    <tr>
        <td>Your Full Name:</td>
        <td><input type="text" name="name" size="32"> *</td>
    
    </tr>
    
    <tr>
        <td>Your Post Code:</td>
        <td><input type="text" name="pcode" size="5"> *</td> 
    </tr>
    
    <tr>
        <td>&nbsp;</td>
        <td><input type="submit" value="Register" name="submit"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>
    checking the input and adding to the database

    Code:
    <!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=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php 
    $user = $_POST['username'];
    $pass = $_POST['password'];
    $pass2 = $_POST['password'];
    $email = $_POST['email'];
    $name = $_POST['name'];
    $pcode = $_POST['pcode'];
    
    
    if (($pass)!=($pass2)) 														//Passwords enterd the same?
    {
    	echo("you have enterd two diffrent passwords, Try Again");				//diffrent passwords enterd error msg
    	Die();
    }
    function CheckMail($email)
    {
    if(eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-z]{2,4}$",$email))    //Proper email address?
    	{ 
    		return true;
    	}
    	else 
    	{ 
    		return false; 
    	}
    }
    
    if ((empty($email)) || (!CheckMail($email)))              //if email is left blank or does not match checkmails regex msg displays
    {
    	echo("email doesnt suit");
    	Die();
    }
    
    function Checkpcode($pcode) 
    {
    	if (eregi("[0-9a-zA-Z]", $pcode)) //check characters
    	{
    		return true;
    	}
    	else 
    	{ 
    		return false; 
    	}
    }
    if ((empty($pcode)) || (!Checkpcode($pcode)) )
    
    {
    	echo("Post code is in the incorrect format ");//error message
    	Die();
    }
    if (empty($name))
    {
    	echo("didnt enter your name stranger"); 
    	Die();
    }
    $min_lenngth = 4;
    if(strlen($user) < $min_lenngth || strlen($pass) < $min_lenngth)
    {
    	echo("Password or usernames to short cmon it only has to be more than 4 letters!!");
    	Die();
    }
    
    
    $conn = mysql_connect("localhost", "root", "");
    @mysql_select_db(thewu) or die( "Unable to select database");
    
    $check = mysql_query("select username from users where username=\"$user\"");
    $returned = mysql_fetch_array($check);
    if(!empty($returned))
    {
    echo("username Is taken"); //the user will be sent told this 
    mysql_close($conn); // close the connection to the database 
    Die();
    }
    else
    {
    	$returned = mysql_fetch_array($check);
    	if(!empty($returned))
    {
    echo("There is allready an account for that email"); //the user will be sent to this page
    mysql_close($link); //and we close the connection to the database
    Die();
    }
    	else 
    	$pass=md5($pass); //Encrypt password
    	$request = "INSERT INTO users (id,fullname,username,password,email,pcode) values
    	(NULL,\'$name\',\'$user\',\'$pass\', \'$email\',\'$pcode\')";
    	
    	
    $results = mysql_query($request);
    if($results)
    {
    echo("added correctly"); //Everythings good record has been added
    }
    else
    	echo("THIS error!");
    	}
     // we close the connection
    Die();
    
    	
    ?>
    </body>
    </html>
    When i run the script all i get is the last echo msg " ("This Error") "
    Any help would be great icant see the problem at all

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    Well, it looks like you missed some braces for the else in this part
    PHP Code:
    else 
        
    $pass=md5($pass); //Encrypt password
        
    $request "INSERT INTO users (id,fullname,username,password,email,pcode) values
        (NULL,\'$name\',\'$user\',\'$pass\', \'$email\',\'$pcode\')"
    ;
        
        
    $results mysql_query($request); 
    Maybe you should try properly indent your code. It will be easier to catch these kind of errors.

    Explicitly closing the database connection shouldn't be necessary. This should happen automatically at the end of the scripts execution.

  • #3
    New to the CF scene
    Join Date
    Mar 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey thanks for the replay and spotting those missisng braces i will indent the code and scour back through for any similiar mostakes hopefully itll be a simple mistake like that. cheers

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    $pass $_POST['password'];
    $pass2 $_POST['password']; //$_POST['password2']; 
    doesnt that 2nd line need editting? other wise it will not check the 2nd password to see if they are the same


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •