Help... i'm a little rusty again :S

Discussion in 'PHP' started by Grit., Mar 24, 2009.

  1. #1
    THis is beginning to drive me a little insane... i know the problem lays in my error checking, and possibly obtaining the form data, can somebody please help me see what's wrong? My code is

    
    
    
    <?php
    
    //Welcome to the register page ^-^
    
    include_once('config.php');
    
    //just a check to see if the user is logged in
    //if they are then they can't register again'
    
    if($logged == "1"){
    	
    	include_once($headerinc);
    	
    	echo 'You are already a registered member. You have no need to register again.<BR />';
    	
    	include_once($footerinc);
    	
    	exit;
    	
    }
    
    if($_POST){
    	
    	//time to get the data from the form
    	
    	$reguser = getprotect($_POST['reguser']);
    	$regmail = getprotect($_POST['regmail']);
    	$regmail2 = getprotect($_POST['regmail2']);
    	$regpass = getprotect($_POST['regpass1']);
    	$regpass2 = getprotect($_POST['regpass2']);
    	$ip = $_SERVER['REMOTE_ADDR'];
    	$regnet = getprotect($_POST['regnet']);
    	
    	
    				//now we've set data into variables, lets go
    				
    				$regerrors = array();
    				
    				if(empty($reguser)){$regerrors[]= "Please enter a username <br />";} ELSE{
    					$reguseravail = "SELECT * FROM user WHERE username='".$reguser."'";
    					$reguseravailrun = mysql_query($reguseravail);
    					$reguseravailcount = mysql_num_rows($reguseravailrun);
    					if($reguseravailcount != 1){$regerrors[]= "The username you have selected is already taken <br />";}
    				}
    				if(empty($regmail)){$regerrors[]= "Please enter an email address <br />";}
    				if(empty($regmail2)){$regerrors[]= "Please confirm your email address <br />";}
    				if($regmail != $regmail2){$regerrors[] = "The email addresses you entered do not match <br />";}
    				if(empty($regpass)){$regerrors[]= "Please enter a password <br />";}
    				if(empty($regpass2)){$regerrors[]= "Please confirm a password <br />";}
    				if($regpass != $regpass2){$regerrors[] = "The passwords you enter do not match <br />";} ELSE {
    					$regpassmd5 = md5($regpass);
    				}
    				
    				
    				if(count($regerrors) == 0){
    					
    					$adduser = "INSERT INTO user ('username', 'password', 'email', 'ip', 'network') VALUES ('".$reguser."','".$regpassmd5."','".$regmail."','".$ip."','".$regnet."')";
    					$runadd = mysql_query($adduser);
    					
    					if($runadd){
    						
    						include_once($headerinc);
    						
    						echo 'Your account was created successfully. Please click <A href="http://www.getfreetopups.co.uk/login.php">HERE</A> to login.';
    						
    					} ELSE {
    						
    						include_once($headerinc);
    						
    						echo 'There was an error creating your account. Please try again.';
    					
    						
    					}
    					
    					
    				} ELSE {
    					
    					include_once($headerinc);
    					
    					echo 'The following errors occurred:<br /><FONT color=#F00';
    					
    					foreach($regerrors as $regerrprint){
    						
    						echo $regerrprint;						
    						
    					}
    					
    					echo'</FONT><br /><br />';
    					
    					echo '
    
    
    <FORM action="register.php" method="post">
    <table width="60%" align="center">
    <tr>
    <td>Username</td>
    <td><input type="text" name="reguser"></td>
    </tr>
    <tr>
    <td>Email</td>
    <td><input type="text" name="regmail"></td>
    </tr>
    <tr>
    <td>Confirm Email</td>
    <td><input type="text" name="regmail2"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td><input type="password" name="regpass1"></td>
    </tr>
    <tr>
    <td>Confirm Password</td>
    <td><input type="password" name="regpass2"></td>
    </tr>
    <tr>
    <td>Phone network</td>
    <td><SELECT name="regnet">
    <option value="O2">O2</option>
    <option value="Orange">Orange</option>
    <option value="Virgin Mobile">Virgin Mobile</option>
    <option value="T-mobile">T-Mobile</option>
    <option value="Tesco Mobile">Tesco Mobile</option>
    <option value="3">3</option>
    </SELECT>
    </td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" value="Register"></td>
    </tr>
    </table>
    </FORM>
    
    ';
    					
    				}
    	
    	
    } else {
    
    
    include_once($headerinc);
    
    echo '
    
    
    <FORM action="register.php" method="post">
    <table width="60%" align="center">
    <tr>
    <td>Username</td>
    <td><input type="text" name="reguser"></td>
    </tr>
    <tr>
    <td>Email</td>
    <td><input type="text" name="regmail"></td>
    </tr>
    <tr>
    <td>Confirm Email</td>
    <td><input type="text" name="regmail2"></td>
    </tr>
    <tr>
    <td>Password</td>
    <td><input type="password" name="regpass1"></td>
    </tr>
    <tr>
    <td>Confirm Password</td>
    <td><input type="password" name="regpass2"></td>
    </tr>
    <tr>
    <td>Phone network</td>
    <td><SELECT name="regnet">
    <option value="O2">O2</option>
    <option value="Orange">Orange</option>
    <option value="Virgin Mobile">Virgin Mobile</option>
    <option value="T-mobile">T-Mobile</option>
    <option value="Tesco Mobile">Tesco Mobile</option>
    <option value="3">3</option>
    </SELECT>
    </td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" value="Register"></td>
    </tr>
    </table>
    </FORM>
    
    ';
    
    }
    
    include_once($footerinc);
    
    ?>
    
    
    
    
    PHP:
     
    Grit., Mar 24, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    What error are you getting?

    Put:

    error_reporting(E_ALL);

    as the first line of php code...
     
    jestep, Mar 24, 2009 IP
    Grit. likes this.
  3. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    getprotect? where is this function?
     
    javaongsan, Mar 24, 2009 IP
  4. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #4
    getprotect is my own function defined in config.php... there are no errors in config.php or my functions defined within it. I know for some reason that this script isn't getting the data from the form at times :S Thank you for the error reporting function. I'll test it, and let you know how that turns out.

    As a question, where does error_reporting(E_ALL); put the error reports?
     
    Grit., Mar 25, 2009 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    It puts it on the page itself. As a general rule, they will be displayed above the script being executed. For instance, say you have a form in a php-file, with lots of PHP before the actual HTML with the form, and you use the error_reporting(E_ALL); on the top, before any of the other PHP - you would get all errors output on the page above the form.
     
    PoPSiCLe, Mar 25, 2009 IP
  6. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #6
    ok, that form just says that there was an issue with a variable i set in config.php, since i tried calling it when it wasn't set, that's now been fixed, however, there is still the same issue. I think i'm going to rewrite the page from scratch, and see if i can make any difference that way. Thank you for your time
     
    Grit., Mar 26, 2009 IP