Jump to content

Registration Form


Flukey

Recommended Posts

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.

Link to comment
Share on other sites

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

this assumes you are using ?page=
so register.php would display the register form
and register.php?page=registered will display the message :)
Link to comment
Share on other sites

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

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.
Link to comment
Share on other sites

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:
[code]<?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>[/code]
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.
Link to comment
Share on other sites

[!--quoteo(post=364319:date=Apr 13 2006, 08:58 AM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 13 2006, 08:58 AM) [snapback]364319[/snapback][/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:
[code]<?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>[/code]
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. :)
Link to comment
Share on other sites

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">:
[code]<br><?=$msg?><br><br>[/code]
and then move </form> immediately after this line:
[code]<input type="submit" name="subreg" value="Create Account">[/code]
Link to comment
Share on other sites

[!--quoteo(post=364403:date=Apr 13 2006, 02:40 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 13 2006, 02:40 PM) [snapback]364403[/snapback][/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">:
[code]<br><?=$msg?><br><br>[/code]
and then move </form> immediately after this line:
[code]<input type="submit" name="subreg" value="Create Account">[/code]
[/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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.