Jump to content


Photo

Registration Form


  • Please log in to reply
7 replies to this topic

#1 Flukey

Flukey
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 13 April 2006 - 02:52 AM

Hey guys,

Ok heres my problem. Basically, i've set up a registration form, and i'm using the POST function in php to get the data and insert it into my MySQL database.

I have all the connection sorted etc... and its all laid out correct.

However, i'm performing validation checks such as whether the user has entered a username, if not it echos out that they haven't filled in the required field, this is all fine.

What one wishes to do is the following:

When a user presses submit, is it possible to clear out the div container the form is in, and clear the page and put in the container "Congratulations you've registered etc..." or will i have to use a different php file?

What would you do?

Thanks a lot,

Regards, Flukey.



#2 echoninja

echoninja
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 13 April 2006 - 03:01 AM

if(!$page) { **your register bit** } 
if($page == "registered") { echo "You have registered succesfully"; }

this assumes you are using ?page=
so register.php would display the register form
and register.php?page=registered will display the message :)

#3 Flukey

Flukey
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 13 April 2006 - 03:07 AM

[!--quoteo(post=364271:date=Apr 13 2006, 04:01 AM:name=EchoNinja)--][div class=\'quotetop\']QUOTE(EchoNinja @ Apr 13 2006, 04:01 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if(!$page) { **your register bit** } 
if($page == "registered") { echo "You have registered succesfully"; }

this assumes you are using ?page=
so register.php would display the register form
and register.php?page=registered will display the message :)
[/quote]

Hey,

Thanks a lot for your fast reply.

At the moment i'm only using [a href=\"http://localhost/project/register.php\" target=\"_blank\"]http://localhost/project/register.php[/a] and i haven't got ?page=whatever set up yet.

What code would i need to set this up.

Thanks a lot. I know php, however i haven't use that part of it.

Cheers.

#4 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 13 April 2006 - 07:58 AM

Having extra tags on the URL is best avoided as it means people can access parts of the script when they shouldn't by typing the URL into the browser directly.

I do my best to contain my scripts, that is, anything for example related to registering an account would be stored in one script to save having loads of scripts and here is how I'd have a register script laid out:
<?php
  $opmode="register"; //Make the form appear so user can register
  if ($_POST['subreg']) { //Has user pressed submit button?
    if ($_POST['usrname']) { //Check if user has entered text into usrname
      $usrname=$_POST['usrname']); //Yes, so let's get it
      //Check if $usrname exists already
      if ($_POST['usremail']) { //Check if user has entered an email
        $usremail=$_POST['usremail']; //Yes so get it
        $fetch=mysql_fetch_array(mysql_query("SELECT username FROM users WHERE `username` LIKE '$usrname'"));
        $username=$fetch[username]; //Check db for existing username
        if (empty($username)) { //If empty then username not already used
          //Make a new account for the user
          $opmode="done"; //We're done so make the "registration successful" message appear
        } else {
          $msg="That username is already in use";
          $usrname=""; //Clear var to stop existing username appear in the forum again
        }
      } else {$msg="You need to enter a valid email";}
    } else {$msg="You need to enter a username";}
  }
?>
<html>
<head>
  <title>Register</title>
</head>
<body>
  <div align="center">
<?php if ($opmode=="register") { ?>
  <form action="register.php" method="post">
  Username <input type="text" name="usrname" size="22" maxlength="20" value="<?=$usrname?>">
  Email <input type="text" name="usremail" size="82" maxlength="80" value="<?=$usremail?>">
  <input type="submit" name="subreg" value="Create Account">
<?php } else if ($opmode=="done") { ?>
  Thank-you for registering.<br><br>
  You can now log in and start using your account.
<?php } ?>
  </form>
  </div>
</body>
</html>
I'm at work now and have just type this off the top of my head so I can't guarantee this code will work but it gives you the basic idea. Basically I'm using a variable called $opmode to contain text telling me what is currently expected to be done. Its in the HTML part of the script that I'm checking this and displaying the relevant output. By adding a load of if...else decisions you can add a load of different types of activity to one script quite safely. There are no values being passed through the URL so users can't really access parts of the script without following the script through the proper channels.

Its simple to add a "verify" routine simply by displaying the registeration information and making a form with hidden attributes.

One last note...

When adding features like this to one script be careful that variables are cleared when conditions change/are met as these may influence different parts of the script.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#5 Flukey

Flukey
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 13 April 2006 - 01:05 PM

[!--quoteo(post=364319:date=Apr 13 2006, 08:58 AM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 13 2006, 08:58 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Having extra tags on the URL is best avoided as it means people can access parts of the script when they shouldn't by typing the URL into the browser directly.

I do my best to contain my scripts, that is, anything for example related to registering an account would be stored in one script to save having loads of scripts and here is how I'd have a register script laid out:
<?php
  $opmode="register"; //Make the form appear so user can register
  if ($_POST['subreg']) { //Has user pressed submit button?
    if ($_POST['usrname']) { //Check if user has entered text into usrname
      $usrname=$_POST['usrname']); //Yes, so let's get it
      //Check if $usrname exists already
      if ($_POST['usremail']) { //Check if user has entered an email
        $usremail=$_POST['usremail']; //Yes so get it
        $fetch=mysql_fetch_array(mysql_query("SELECT username FROM users WHERE `username` LIKE '$usrname'"));
        $username=$fetch[username]; //Check db for existing username
        if (empty($username)) { //If empty then username not already used
          //Make a new account for the user
          $opmode="done"; //We're done so make the "registration successful" message appear
        } else {
          $msg="That username is already in use";
          $usrname=""; //Clear var to stop existing username appear in the forum again
        }
      } else {$msg="You need to enter a valid email";}
    } else {$msg="You need to enter a username";}
  }
?>
<html>
<head>
  <title>Register</title>
</head>
<body>
  <div align="center">
<?php if ($opmode=="register") { ?>
  <form action="register.php" method="post">
  Username <input type="text" name="usrname" size="22" maxlength="20" value="<?=$usrname?>">
  Email <input type="text" name="usremail" size="82" maxlength="80" value="<?=$usremail?>">
  <input type="submit" name="subreg" value="Create Account">
<?php } else if ($opmode=="done") { ?>
  Thank-you for registering.<br><br>
  You can now log in and start using your account.
<?php } ?>
  </form>
  </div>
</body>
</html>
I'm at work now and have just type this off the top of my head so I can't guarantee this code will work but it gives you the basic idea. Basically I'm using a variable called $opmode to contain text telling me what is currently expected to be done. Its in the HTML part of the script that I'm checking this and displaying the relevant output. By adding a load of if...else decisions you can add a load of different types of activity to one script quite safely. There are no values being passed through the URL so users can't really access parts of the script without following the script through the proper channels.

Its simple to add a "verify" routine simply by displaying the registeration information and making a form with hidden attributes.

One last note...

When adding features like this to one script be careful that variables are cleared when conditions change/are met as these may influence different parts of the script.
[/quote]


Hey. Thanks a lot, i really appreciate that. I'm just going to do that now. I'll report if everything works :)

Cheers. :)

#6 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 13 April 2006 - 01:40 PM

You're welcome :)

Just noticed an error, I didn't show $msg to the user so messages wouldn't appear. Add this line after <div align="center">:
<br><?=$msg?><br><br>
and then move </form> immediately after this line:
<input type="submit" name="subreg" value="Create Account">

Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#7 Flukey

Flukey
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts

Posted 13 April 2006 - 07:56 PM

[!--quoteo(post=364403:date=Apr 13 2006, 02:40 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 13 2006, 02:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You're welcome :)

Just noticed an error, I didn't show $msg to the user so messages wouldn't appear. Add this line after <div align="center">:
<br><?=$msg?><br><br>
and then move </form> immediately after this line:
<input type="submit" name="subreg" value="Create Account">
[/quote]

Thanks alot. I've just finished coding it, got all the validation working and inserting into database functions working. Cheers. Works like a charm :)

#8 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 14 April 2006 - 08:41 AM

Glad to hear it. :D
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users