Jump to content

Registration script problem


Smee

Recommended Posts

I am having a problem with my registration script that i can't get my head around.

 

Basically whats happening is if there is an error in the script, the PHP shows an image and the words 'problems with registration' as shown below.

 

$error = true;
   echo '<h2><p><img src="/images/registrationproblem.png" width="16" height="16" alt="Forgot Password" title="Forgot Password" align="baseline" border="0" hspace="10" />Problems with Registration:</p></h2>';

 

after it will <li> list of the problems that occured. When you first load register.php it does not show up, this is correct however when a successfull registration has been made it still shows the image with the words 'registration problems'.

 

(hope that made sense)

 

Anyway here is the entire script and thanks for any help!

 


<?php # register.php

// This is the registration script for the site

require_once ('./includes/config.inc.php');

// Set the page title and header

$page_title = 'Register for Football Trip';

include ('./includes/header.html');

?>

    	<div id="registration_content_container">
        	
            <div id="content_header">
            </div>

    <h1> Register for Football Trip
    <br />
<br />

<p>To access Football Trip.net please complete this short registration form. </p></h1>

<div id="registration">
           
<form action="register.php" method="post">
            
            <p class="first_name"><label> First Name: </label>
<input type="text" name="first_name" maxlength="15" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?>" />

            <p class="last_name"><label> Last Name: </label> 
<input type="text" name="last_name" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" />

            <p class="email"><label> E-Mail Address: </label>
<input type="text" name="email" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />

<label><small>** Please enter your email address carefully, it will be used to<br /> retrieve a forgotten password and contact you in the future.**</small></label>

          <p class="password1"><label> Password: </label>
<input type="password" name="password1" maxlength="20" />
            <label><small> **Use only letters and numbers. Must be between 4 and 20 Characters long.** </small></label>

          <p class="password2"><label> Confirm Password: </label>
<input type="password" name="password2" maxlength="20" />

	<p class="post_code"><label> Post Code: </label> 
        <select name="post_code">
        <option>AB 	Aberdeen</option> 	
        <option>AL 	St Albans</option> 	
        <option>B 	Birmingham</option> 	
        <option>BA 	Bath</option> 	
        <option>BB 	Blackburn</option> 	
        <option>BD 	Bradford</option> 	
        <option>BH 	Bournemouth</option> 	
        <option>BL 	Bolton</option> 	
        <option>BN 	Brighton</option> 	
        <option>BR 	Bromley</option> 	
        <option>BS 	Bristol</option> 	
        <option>BT 	Belfast</option> 	
        <option>CA 	Carlisle</option> 	
        <option>CB 	Cambridge</option> 	
        <option>CF 	Cardiff</option> 	
        <option>CH 	Chester</option> 	
        <option>CM 	Chelmsford</option> 	
        <option>CO 	Colchester</option> 	
        <option>CR 	Croydon</option> 	
        <option>CT 	Canterbury</option> 	
        <option>CV 	Coventry</option> 	
        <option>CW 	Crewe</option> 	
        <option>DA 	Dartford</option> 	
        <option>DD 	Dundee</option> 	
        <option>DE 	Derby</option> 	
        <option>DG 	Dumfries</option>
        <option>DH 	Durham</option> 	
        <option>DL 	Darlington</option> 	
        <option>DN 	Doncaster</option> 	
        <option>DT 	Dorchester</option> 	
        <option>DY 	Dudley</option> 	
        <option>E 	London E</option> 	
        <option>EC 	London EC</option> 	
        <option>EH 	Edinburgh</option> 	
        <option>EN 	Enfield</option> 	
        <option>EX 	Exeter</option> 	
        <option>FK 	Falkirk and Stirling</option> 	
        <option>FY 	Blackpool</option>
        <option>G 	Glasgow</option> 	
        <option>GL 	Gloucester</option> 	
        <option>GU 	Guildford</option> 	
        <option>HA 	Harrow</option> 	
        <option>HD 	Huddersfield</option> 	
        <option>HG 	Harrogate</option> 	
        <option>HP 	Hemel Hempstead</option> 	
        <option>HR 	Hereford</option> 	
        <option>HS 	Outer Hebrides</option> 	
        <option>HU 	Hull</option> 	
        <option>HX 	Halifax</option> 	
        <option>IG 	Ilford</option> 	
        <option>IP 	Ipswich</option> 	
        <option>IV 	Inverness</option> 	
        <option>KA 	Kilmarnock</option> 	
        <option>KT 	Kingston upon Thames</option> 	
        <option>KW 	Kirkwall</option> 	
        <option>KY 	Kirkcaldy</option> 	
        <option>L 	Liverpool</option> 	
        <option>LA 	Lancaster</option> 	
        <option>LD 	Llandrindod Wells</option>	
        <option>LE 	Leicester</option> 	
        <option>LL 	Llandudno</option> 	
        <option>LN 	Lincoln</option> 	
        <option>LS 	Leeds</option> 	
        <option>LU 	Luton</option> 	
        <option>M 	Manchester</option> 	
        <option>ME 	Rochester</option>
        <option>MK 	Milton Keynes</option> 	
        <option>ML 	Motherwell</option> 	
        <option>N 	London N</option> 	
        <option>NE 	Newcastle upon Tyne</option> 	
        <option>NG 	Nottingham</option> 	
        <option>NN 	Northampton</option> 	
        <option>NP 	Newport</option> 	
        <option>NR 	Norwich</option> 	
        <option>NW 	London NW</option> 	
        <option>OL 	Oldham</option> 	
        <option>OX 	Oxford</option> 	
        <option>PA 	Paisley</option> 	
        <option>PE 	Peterborough</option> 	
        <option>PH 	Perth</option> 	
        <option>PL 	Plymouth</option> 	
        <option>PO 	Portsmouth</option> 	
        <option>PR 	Preston</option> 	
        <option>RG 	Reading</option> 	
        <option>RH 	Redhill</option> 	
        <option>RM 	Romford</option> 	
        <option>S 	Sheffield</option> 	
        <option>SA 	Swansea</option> 	
        <option>SE 	London SE</option> 	
        <option>SG 	Stevenage</option> 	
        <option>SK 	Stockport</option> 	
        <option>SL 	Slough</option> 	
        <option>SM 	Sutton</option> 	
        <option>SN 	Swindon</option> 	
        <option>SO 	Southampton</option> 	
        <option>SP 	Salisbury</option>
        <option>SR 	Sunderland</option> 	
        <option>SS 	Southend-on-Sea</option> 	
        <option>ST 	Stoke-on-Trent</option> 	
        <option>SW 	London SW</option> 	
        <option>SY 	Shrewsbury</option> 	
        <option>TA 	Taunton</option> 	
        <option>TD 	Galashiels</option>
        <option>TF 	Telford</option> 	
        <option>TN 	Tonbridge</option>
        <option>TQ 	Torquay</option> 	
        <option>TR 	Truro</option> 	
        <option>TS 	Cleveland</option>
        <option>TW 	Twickenham</option> 	
        <option>UB 	Southall</option>
        <option>W 	London W</option> 	
        <option>WA 	Warrington</option> 	
        <option>WC 	London WC</option> 	
        <option>WD 	Watford</option> 	
        <option>WF 	Wakefield</option> 	
        <option>WN 	Wigan</option> 	
        <option>WR 	Worcester</option> 	
        <option>WS 	Walsall</option> 	
        <option>WV 	Wolverhampton</option> 	
        <option>YO 	York</option> 	
        <option>ZE 	Lerwick</option>
        </select>

	<p class="team_supported"><label> Football Team Supported: </label> 
        <select name="team_supported">	
        <option>Accrington Stanley</option>
        <option>Aldershot</option>
        <option>Arsenal</option>
        <option>Aston Villa</option>
        <option>Barnet</option>
        <option>Barnsley</option>
        <option>Birmingham City</option>
        <option>Blackburn Rovers</option>
        <option>Blackpool</option>
        <option>Bolton</option>
        <option>Bournemouth</option>
        <option>Bradford City</option>
        <option>Brentford</option>
        <option>Brighton</option>
        <option>Bristol City</option>
        <option>Bristol Rovers</option>
        <option>Burton Albion</option>
        <option>Bury</option>
        <option>Cardiff City</option>
        <option>Carlisle</option>
        <option>Charlton Athletic</option>
        <option>Chelsea</option>
        <option>Cheltenham Town</option>
        <option>Chesterfield</option>
        <option>Colchester United</option>
        <option>Coventry City</option>
        <option>Crewe Alexandra</option>
        <option>Crystal Palace</option>
        <option>Dagenham and Redbridge</option>
        <option>Darlington</option>
        <option>Derby County</option>
        <option>Doncaster Rovers</option>
        <option>Everton</option>
        <option>Exeter City</option>
        <option>Fulham</option>
        <option>Gillingham</option>
        <option>Grimsby Town</option>
        <option>Hartlepool United</option>
        <option>Hereford United</option>
        <option>Huddersfield Town</option>
        <option>Hull City</option>
        <option>Ipswich Town</option>
        <option>Leeds United</option>
        <option>Leicester City</option>
        <option>Leyton Orient</option>
        <option>Lincoln City</option>
        <option>Liverpool</option>
        <option>Macclesfield Town</option>
        <option>Manchester City</option>
        <option>Manchester United</option>
        <option>Middlesbrough</option>
        <option>Millwall</option>
        <option>Milton Keynes Dons</option>
        <option>Morecambe</option>
        <option>Newcastle United</option>
        <option>Northampton Town</option>
        <option>Norwich</option>
        <option>Nottingham Forest</option>
        <option>Notts County</option>
        <option>Oldham Athletic</option>
        <option>Peterborough United</option>
        <option>Plymouth Argyle</option>
        <option>Port Vale</option>
        <option>Portsmouth</option>
        <option>Preston North End</option>
        <option>Queens Park Rangers</option>
        <option>Reading</option>
        <option>Rochdale</option>
        <option>Rotherham United</option>
        <option>Scunthorpe United</option>
        <option>Sheffield United</option>
        <option>Sheffield Wednesday</option>
        <option>Shrewsbury Town</option>
        <option>Southampton</option>
        <option>Southend United</option>
        <option>Stockport</option>
        <option>Stoke City</option>
        <option>Sunderland</option>
        <option>Swansea City</option>
        <option>Swindon Town</option>
        <option>Torquay United</option>
        <option>Tottenham Hotspur</option>
        <option>Trenmere Rovers</option>
        <option>Wallsall</option>
        <option>Watford</option>
        <option>West Bromwich Albion</option>
        <option>West Ham United</option>
        <option>Wigan Athletic</option>
        <option>Wolverhampton Wanderers</option>
        <option>Wycombe Wanderers</option>
        <option>Yeovil Town</option>
        </select>

           
	  <p class="submit">
<input type="submit" name="submit" value="Register" />
            
  </form>
         </div>
         
         <div id="registration_error">  
<?php

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

require_once ('../mysql_connect.php');

$error = true;
   echo '<h2><p><img src="/images/registrationproblem.png" width="16" height="16" alt="Forgot Password" title="Forgot Password" align="baseline" border="0" hspace="10" />Problems with Registration:</p></h2>';

$error = false;

if (preg_match ('/^[[:alpha:]\.\'\-]{2,30}$/i', stripslashes(trim($_POST['first_name'])))) {
   $fn = mysql_real_escape_string($_POST['first_name']);
}else {
   $error = true;
   echo '<h2><li><font color ="red"> Please enter your first name!</font></li></h2>';
}        

if (preg_match ('/^[[:alpha:]\.\'\-]{2,30}$/i', stripslashes(trim($_POST['last_name'])))) {
   $ln = mysql_real_escape_string($_POST['last_name']);
}else {
   $error = true;
   echo '<h2><li><font color ="red"> Please enter your last name!</font></li></h2>';
}

if (preg_match ('/^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$/i', stripslashes(trim($_POST['email'])))) {
   $e = mysql_real_escape_string($_POST['email']);
}else {
   $error = true;   
   echo '<h2><li><font color ="red"> Please enter a correct e-mail address</font></li></h2>';
}

if (preg_match ('/^[[:alnum:]]{4,20}$/i', stripslashes(trim($_POST['password1'])))) {
   if ($_POST['password1'] == $_POST['password2']) {
      $p = mysql_real_escape_string($_POST['password1']);
   }else {
      $error = true;	  
      echo '<h2><li><font color="red">Your password did not match the confirmed password!</font></li><h2>';
   }
}else {
   $error = true;  
   echo '<h2><li><font color="red">Please enter a valid password</font></li></h2>';
}

?>

</div>

<?php

$pc = mysql_real_escape_string($_POST['post_code']);
$ts = mysql_real_escape_string($_POST['team_supported']);
               
if (!$error) {
   $query ="SELECT user_id FROM users WHERE email='$e'";
   $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: ".mysql_error());
      
   if (mysql_num_rows($result) == 0) {
      $a = md5(uniqid(rand(), true));
      $query = "INSERT INTO users (email, pass, first_name, last_name, post_code, team_supported, active, registration_date) VALUES ('$e', '$p', '$fn', '$ln', '$pc', '$ts', '$a', NOW() )";
      $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error:" .mysql_error());
   
      if (mysql_affected_rows() == 1) {
         $body = "Thank you for registering with Football Trip. Please use the link below to activate your account:\n\n";
         $body .= "http://www.footballtrip.net/activate.php?x=" . mysql_insert_id() . "&y=$a";
         mail($_POST['email'],'Registration Comfirmation',$body);

	echo '<center><h1><p><img src="/images/registrationconfirmation.png" width="16" height="16" align="baseline" border="0" hspace="10" />Thank You for Registering! <br /><br />
	A confirmation E-Mail has been sent to the address given, You must use the <br />
	link provided in order to activate your account.</p></h1></center>';		 
      }else {
         echo '<center><h1><p><font color="red"> You could not be registered due to a system error. We apologize for any inconvenience.                           </font></p></h1></center>';
      }
   }else {
      echo '<center><h1><p><font color="red"> That E-Mail address has already been registered.<br />
  Forgotten your password?, Click <a href="/forgot_password.php /> here </a>.</font></p></h1></center>';
   }
} else { 
   echo '<center><h1><p><font color="red"> There Were Problems With the Registration. Please Try Again.</font></p></h1></center>';
}
      
mysql_close();

}

?>

</div>

<?php
// Include the HTML footer.
include ('./includes/footer.html');
?>

Link to comment
https://forums.phpfreaks.com/topic/203549-registration-script-problem/
Share on other sites

It seems that no matter what with that like that every time the form been submitted that this particular echo shown below will always be displayed? Is that what that is doing there?

<?php

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

require_once ('../mysql_connect.php');

$error = true;
      echo '<h2><p><img src="/images/registrationproblem.png" width="16" height="16" alt="Forgot Password" title="Forgot Password" align="baseline" border="0" hspace="10" />Problems with Registration:</p></h2>';

$error = false;

 

Shouldn't there be an if statement that says hey... this is true... not just run every time I mean?

Well that's the problem, instead of that echo being there... You want it at the end. Then within each of the error checking areas have an array that stores all the errors instead of echoing them at the check

 

I meant that you should do something like this.... Notice I moved the picture print to the end and instead of echo each code as you get it, store the error in an array then print out the errors and still have you picture before the error codes. This should work if I didn't make a typo.


<?php

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

require_once ('../mysql_connect.php');


$array_er = array();
$error = false;

if (preg_match ('/^[[:alpha:]\.\'\-]{2,30}$/i', stripslashes(trim($_POST['first_name'])))) {
   $fn = mysql_real_escape_string($_POST['first_name']);
}else {
   $error = true;
   array_push( $array_er, '<h2><li><font color ="red"> Please enter your first name!</font></li></h2>');
}        

if (preg_match ('/^[[:alpha:]\.\'\-]{2,30}$/i', stripslashes(trim($_POST['last_name'])))) {
   $ln = mysql_real_escape_string($_POST['last_name']);
}else {
   $error = true;
   array_push( $array_er, '<h2><li><font color ="red"> Please enter your last name!</font></li></h2>');
}

if (preg_match ('/^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$/i', stripslashes(trim($_POST['email'])))) {
   $e = mysql_real_escape_string($_POST['email']);
}else {
   $error = true;   
   array_push( $array_er, '<h2><li><font color ="red"> Please enter a correct e-mail address</font></li></h2>');
}

if (preg_match ('/^[[:alnum:]]{4,20}$/i', stripslashes(trim($_POST['password1'])))) {
   if ($_POST['password1'] == $_POST['password2']) {
      $p = mysql_real_escape_string($_POST['password1']);
   }else {
      $error = true;     
      array_push( $array_er,  '<h2><li><font color="red">Your password did not match the confirmed password!</font></li><h2>');
   }
}else {
   $error = true;  
   array_push( $array_er, '<h2><li><font color="red">Please enter a valid password</font></li></h2>');
}



if ( $error == true){
      echo '<h2><p><img src="/images/registrationproblem.png" width="16" height="16" alt="Forgot Password" title="Forgot Password" align="baseline" border="0" hspace="10" />Problems with Registration:</p></h2>';
      foreach ($array_er as &$error_code) {echo $error_code;}
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.