logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 03-20-2012, 05:19 PM   #1
sydesign
 
Join Date: Jan 2011
Posts: 41
Default PHP register form error

I am working on a membership registration form for a site and for some reason my code isn't working. looking through it i don't see anything that stands out as an error. but when I hit the submit button it just goes to a blank page. Is there something wrong with my code?

PHP Code:
<?php
    
    
if($_POST['registerbtn'] ){
        
$getuser $_POST['user'];
        
$getemail $_POST['email'];    
        
$getpass $_POST['pass'];
        
$getretypepass $_POST['retypepass'];
        
        if(
$getuser){
            if(
$getemail){
                if(
$getpassword){
                    if(
$getretypepass){
                        if (
$getpass === $getretypepass ){
                            if((
strlen($getemail) >= 7) && (strstr($getemail"@")) && (strstr(getemail".")) ){
                                require(
"./connect.php");
                                
                                
$query mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                
$numrows mysql_num_rows($query);
                                if (
$numrows == 0){
                                    
$query mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                    
$numrows mysql_num_rows($query);
                                    if (
$numrows == 0){
                                        
                                        
$password md5(md5("hJKHiug897".$password."hjklHhgKJHG8"));
                                        
$date date("F d, Y");
                                        
$code md5(rand());
                                        
                                        
mysql_query("INSERT INTO users VALUES ('', '$getuser', $password', '$getemail', '0', '$code', '$date')");
                                        
                                        
$query mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                        
$numrows mysql_num_rows ($query);
                                        if (
$numrows == 1){
                                            
                                            
$site "http://localhost/TBN";
                                            
$webmaster "Mark Sy <mark@sydesigngraphics.com>";
                                            
$headers "From: $webmaster";
                                            
$subject "Activate your Account";
                                            
$message "Thankyou for registering. Click the link below to activate your account.\n";
                                            
$message .= "$site/activate.php?user=$getuser&code=$code\n";
                                            
$message .= "You must activate your account to login.";
                                            
                                            if (
mail($getemail$subject$message$headers) ){
                                                
$errormsg "You have been registered. You must activate your account from the activation link to <b>$getemail</b>.";
                                                
$getuser "";
                                                
$getemail "";
                                            }
                                            else
                                                
$errormsg "An error has occured. Your activation email was not sent.";
                                        }
                                        else
                                            
$errormsg "An error has occured. Your account was not created.";
                                    }
                                    else 
                                        
$errormsg "There is already a user with that email.";
                                }
                                else 
                                    
$errormsg "There is already a user with that username.";
                                
                                
mysql_close();                                
                            }
                            else
                                
$errormsg "You must enter a valid email address to register.";
                        }
                        else
                            
$errormsg "Your passwords did not match.";
                    }
                    else
                        
$errormsg "You must retype your password to register.";
                }
                else
                    
$errormsg "You must enter your password to register.";
            }
            else
                
$errormsg "You must enter your email to register.";
        }
        else
            
$errormsg "You Must enter your username to register.";
    }
    else
    
    
$form "<form action='./register.php' method='post'>
    <table>
    <tr>
        <td></td>
        <td><font color='red'>
$errormsg</font></td>
    </tr>
    <tr>
        <td>Username:</td>
        <td><input type='text' name='user' value='
$getuser'></td>
    </tr>    <tr>
        <td>Email:</td>
        <td><input type='text' name='email' value='
$getemail'></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type='password' name='pass' value=''></td>
    </tr>
    <tr>
        <td>Retype:</td>
        <td><input type='password' name='retypepass' value=''></td>
    </tr>
    <tr>
        <td></td>
        <td><input type='submit' name='registerbtn' value='register'></td>
    </tr>
    </table>
    </form>"
;
    
    echo 
$form;

?>
sydesign is offline   Reply With Quote
Old 03-20-2012, 08:17 PM   #2
sydesign
 
Join Date: Jan 2011
Posts: 41
Default

ok i fixed some of the original errors i noticed after posting this here is my current code. the error i get now is "An error has occurred. Your account was not created." which I'm assuming occurs at
PHP Code:
if ($numrows == 1){ 
I switched the form and the variables to the top which i noticed helps them work visually (when a submit error occurs yet the $getemail etc. stays in the form) however I'm not sure if it messes up any other part of the code. i just did it when i was playing around with it. the same error seems to occur when when i had the variable in the original spot too so i thought it to be no pertinent to the current issue. (whether or not it is causing another issue)

PHP Code:
<?php
    
    $getuser 
$_POST['user'];
    
$getemail $_POST['email'];    
    
$getpass $_POST['pass'];
    
$getretypepass $_POST['retypepass'];

    
    
$form "<form action='./register.php' method='post'>
    <center><div style='background-image:url(images/memberegister.gif); background-repeat: no-repeat; width: 343px; height:120px; margin-top:50px;'></div><br />
    <table style='background-color:#f0f0f0; padding:40px; border-style:solid; border-width:1px; border-color:#999;'>
    <tr>
        <td>Username:</td>
        <td><input type='text' name='user' value='
$getuser'></td>
    </tr>    <tr>
        <td>Email:</td>
        <td><input type='text' name='email' value='
$getemail'></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><input type='password' name='pass' value=''></td>
    </tr>
    <tr>
        <td>Retype:</td>
        <td><input type='password' name='retypepass' value=''></td>
    </tr>
    <tr>
        <td></td>
        <td><input type='submit' name='registerbtn' value='register'></td>
    </tr>
    </table>
    <h6>&copy; The Buying Networks, LLC.</h6>
    </center>
    </form>"
;
    
    if(
$_POST['registerbtn']){
        
        if(
$getuser){
            if(
$getemail){
                if(
$getpass){
                    if(
$getretypepass){
                        if (
$getpass === $getretypepass ){
                            if((
strlen($getemail) >= 7) && (strstr($getemail"@")) && (strstr($getemail".")) ){
                                require(
"./connect.php");
                                
                                
$query mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                
$numrows mysql_num_rows($query);
                                if (
$numrows == 0){
                                    
$query mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                    
$numrows mysql_num_rows($query);
                                    if (
$numrows == 0){
                                        
                                        
$password md5(md5("hJKHiug897".$password."hjklHhgKJHG8"));
                                        
$date date("F d, Y");
                                        
$code md5(rand());
                                        
                                        
mysql_query("INSERT INTO users VALUES ('', '$getuser', $password', '$getemail', '0', '$code', '$date')");
                                        
                                        
$query mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                        
$numrows mysql_num_rows ($query);
                                        if (
$numrows == 1){
                                            
                                            
$site "http://localhost/TBN";
                                            
$webmaster "Mark Sy <mark@sydesigngraphics.com>";
                                            
$headers "From: $webmaster";
                                            
$subject "Activate your Account";
                                            
$message "Thank you for registering. Click the link below to activate your account.\n";
                                            
$message .= "$site/activate.php?user=$getuser&code=$code\n";
                                            
$message .= "You must activate your account to login.";
                                            
                                            if (
mail($getemail$subject$message$headers) ){
                                                echo 
"You have been registered. You must activate your account from the activation link to <b>$getemail</b>.";
                                                
$getuser "";
                                                
$getemail "";
                                            }
                                            else
                                                echo 
"<center><font color='red'>An error has occurred. Your activation email was not sent. </center></font>$form";
                                        }
                                        else
                                            echo 
"<center><font color='red'>An error has occurred. Your account was not created.</center></font>$form";
                                    }
                                    else 
                                        echo 
"<center><font color='red'>There is already a user with that email.</center></font>$form";
                                }
                                else 
                                    echo 
"<center><font color='red'>There is already a user with that username.</center></font>$form";
                                
                                
mysql_close();                                
                            }
                            else
                                echo 
"<center><font color='red'>You must enter a valid email address to register.</center></font>$form";
                        }
                        else
                            echo 
"<center><font color='red'>Your passwords did not match.</center></font>$form";
                    }
                    else
                        echo 
"<center><font color='red'>You must retype your password to register.</center></font>$form";
                }
                else
                    echo 
"<center><font color='red'>You must enter your password to register.</center></font>$form";
            }
            else
                echo 
"<center><font color='red'>You must enter your email to register.</center></font>$form";
        }
        else
            echo 
"<center><font color='red'>You must enter your username to register.</center></font>$form";
    }
    else
    
    echo 
$form;

?>
sydesign is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:37 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com