A Simple Register Script - This Is a Very Simple Register-Script

free web hosting
Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > PHP

A Simple Register Script - This Is a Very Simple Register-Script

Feelay
Some time ago, i made a login-script.
But how do you use a login-script, if you can't register.
So this morning, I decided to make a register-script..


What you should already know:
The php basics and a little more.
How to use php and mysql together.
The HTML basics (to make the forms).



The first thing we should do, is creating the database tables. Here is the code:

CODE
CREATE TABLE `user` (
  `id` int(4) unsigned NOT NULL auto_increment,
  `username` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  `level` int(4) default '1',
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1;


The first thing we do, is adding the "id" column. Nothing important with that one.
Then we add the "username" and "password" columns. Nothing important here either.
But then, we add the "level" column. In my login script, i have an admin system. This is why i made the "level" column. The default value is 1.. but if you change it to 9, the user will become an admin.



Now Lets Move On to "reg.php"
CODE
<?php
require_once 'database.php';
?>

<h1><strong>Register</strong></h1>

<form name="register" method="post" action="regcheck.php">
  <label>
  <input type="text" name="user" id="user">
  </label>
  Username <br><br>
    <label>
  <input type="password" name="pass" id="pass">
  Password<br />
  </label><label>
  <input type="submit" name="reg" id="reg" value="Register">
  </label>
</form>
<label></label>

<form name="Back" method="post" action="Login.php">
  <input type="submit" name="back" id="back" value="Back to Home">
<p> </p>


The first thing I do, is requiring the "database.php".
It will open a connection to the database.

Then, we add the forms and buttons
It isn't harder than that. Now we have the Register Page


Now, we need the regcheck.php page.

CODE
<?php
if(
    isset( $_POST['user'] ) &&
    isset( $_POST['pass'] )
)
{
    if( strlen( $_POST['user'] ) < 4 )
    {
        echo "Username Must Be More Than 4 Characters.";
    }
    elseif( strlen( $_POST['pass'] ) < 4 )
    {
        echo "Passwrod Must Be More Than 4 Characters.";
    }
    elseif( $_POST['pass'] == $_POST['user'] )
    {
        echo"Username And Password Can Not Be The Same.";
    }
    else
    {
        include( 'database.php' );

        $username = mysql_real_escape_string( $_POST['user'] );
        $password = md5( $_POST['pass'] );

        $sqlCheckForDuplicate = "SELECT username FROM user WHERE username = '". $username ."'";

        
        if( mysql_num_rows( mysql_query( $sqlCheckForDuplicate ) ) == 0 )
        {
            $sqlRegUser =     "INSERT INTO
                        user( username, password )
                    VALUES(
                        '". $username ."',
                        '". $password ."'
                        )";

            if( !mysql_query( $sqlRegUser ) )
            {
                echo "You Could Not Register Because Of An Unexpected Error.";
            }
            else
            {
                echo "You Are Registered And Can Now Login";
                $formUsername = $username;
                
                header ('location: Login.php');
            }
        }
        else
        {
            echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.";
            $formUsername = $username;
        }
    }
}
else
{
    echo "You Could Not Be Registered Because Of Missing Data.";
}
?>



Now the first thing we do here, is to check if the password and user field is checked.
If they are, we check if the fields are more than 4 characters.
And then, we check if the password is the same as the username.
If no errors occurred, we include the database.php
Then make 2 variables.

The $username variable, and the $password variable.
As you can see, the password is md5 protected.

Then we check if the username exists.
if it doesn't, the account will be registered,
and the user will be redirected to the index.php page.
But.. If it is being used, the code will write that the username is being used.


As you can see, i do include the database.php in both files.
Here it is:

CODE
<?
$con = mysql_connect('localhost','mysql_username','mysql_password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db('mysql_database');
?>


The first thing we do here, is:
Start the connection to the database server.
If it couldn't connect, an error will occur.
Then, we select the database we want to use.


This is my third tutorial. Tell me if you liked it, and if you found any errors. tell me, and I will change them.

 

 

 


Reply

Normano
U made many help full tutorials, however I think u forgot the <?php in the regcheck.php page, thanks for the tutorials happy.gif

Reply

Archimedes
In the regcheck.php document, you forgot some of the echo commands.

CODE
Line 16;
  "Username And Password Can Not Be The Same.";
Should be;
echo "Username And Password Can Not Be The Same.";

CODE
Line 42;
"You Are Registered And Can Now Login";
Should be;
echo "You Are Registered And Can Now Login";

CODE
Line 50;
"The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.";
Should be;
echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.";

CODE
Line 57;
  "You Could Not Be Registered Because Of Missing Data.";
Should be;
echo   "You Could Not Be Registered Because Of Missing Data.";


Other than that, nice job.

 

 

 


Reply

Feelay
QUOTE
U made many help full tutorials, however I think u forgot the <?php in the regcheck.php page, thanks for the tutorials
haha ^.^ Thanks for the comment smile.gif

QUOTE
In the regcheck.php document, you forgot some of the echo commands.


CODE
Line 16;
"Username And Password Can Not Be The Same.";
Should be;
echo "Username And Password Can Not Be The Same.";


CODE
Line 42;
"You Are Registered And Can Now Login";
Should be;
echo "You Are Registered And Can Now Login";


CODE
Line 50;
"The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.";
Should be;
echo "The Username You Have Chosen Is Already Being Used By Another User. Please Try Another One.";


CODE
Line 57;
"You Could Not Be Registered Because Of Missing Data.";
Should be;
echo "You Could Not Be Registered Because Of Missing Data.";


Other than that, nice job.


So.. changed them. Thanks for the comment smile.gif

//Feelay

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. register php script - 18.14 hr back. (3)
Similar Topics

Keywords : simple, register, script, simple, register, script

  1. Creating A Php Login Script
    A thorough look at the process behind it (3)
  2. Attack Script In Php
    This is a funny attack script that i made (5)
    Hey! I am going to share an attack script that i made for some time ago. I made it, as a test
    for my game.. And ofc, you can use it for your game to. It is still version 1.0. But I want you to
    learn something from it /wink.gif" style="vertical-align:middle" emoid=";)" border="0"
    alt="wink.gif" /> This is my second tutorial here, and I will try to make it better than my first
    one /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Here is
    the SQL File. CODE CREATE TABLE `characterss` (   `health` int(2....
  3. Very Simple Login-script
    This is a very simple and secure login-script (18)
    Hi. This is my first post here. please Tell me if i do something wrong. This is a very simple and
    secure login script. I will try to add as many comments as possible, to make it easier to
    understand. Lets start with the database. Just make a new SQL file, and call it whatever you want.
    Paste this code: CODE CREATE TABLE `user` (   `id` int(4) unsigned
    NOT NULL auto_increment,   `username` varchar(32) NOT NULL,   `password`
    varchar(32) NOT NULL,   `level` int(4) default '1',   PRIM....
  4. Simple User Validation Script
    (5)
    This tutorial will show you how to create a simple user validation script with PHP. We will need
    two files: "protect.php" and "login.php". The protect file is not meant to be viewed by itself. In
    order to protect a page, you need to include that file by using PHP code like the following: CODE
    include("protect.php"); Keep in mind that this needs to be in between your
    tags. This bit of code uses the include function. It is a handy function that reads all the
    information contained in one file and temporarily adds it to another. For example, this c....
  5. PHP Tutorial: Form Verification And Simple Validation
    A One Page script for PHP form verification. (12)
    Having used various means of verifying HTML forms I believe that this method of verifying a form
    to be the best mostly because it does everything on one page. It presents the form on one page and
    then when the submit button is pressed, if all the required fields are not filled out then it will
    present the form again with all the fields intact and in red lettering will point out the fields
    that are required to be filled out in red. It is not possible to click submit using this method even
    if the user has turned JavaScript off. While it is possible to use javascript to ....
  6. PHP Tutorial: Menu Or Sidebar Script For CMS101
    and other applications as well (6)
    A Php Menu-builder Tutorial This Sidebar Menu-builder code and the php scripts are adapted from
    a Tutorial on the Astahost.com Forum titled : CMS101 - Content Management System Design .
    Since the original tutorial's author (vujsa) did such a marvellous job of describing the system
    in the original Topic posting, I will not attempt to explain it here, rather, I invite you to have a
    look at his Topic and learn from it. The Basic tutorial provided coding for developing a table-based
    web-site template which used php includes and embedded data to create a &....
  7. Creating Your Own Image Gallery With Php
    A Guideline, Not A Complete Script (3)
    Recently a member asked how to create a photo gallery using his various directories filled with
    image files. Here is an overview of the steps and fuctions needed to do this. Assuming that the
    following directories exists and are full of image files: www.testsite.web/photos/gallery1/
    www.testsite.web/photos/gallery2/ www.testsite.web/pictures/album1/ In order to get the contents
    for a specific gallery you'll need to let the script know which one to look in. You'll need
    to use a link that carries the arguments needed to locate the right photos. www.testsite.we....
  8. PHP: Writing A Generic Login And Register Script
    (14)
    Now there are basically 3 functions that a user management system provides: login, register, and
    protection. A user management system can do more than this but that is all that this tutorial will
    be covering. I will try to explain what I am doing as I go along but to fully understand what is
    happening you should have a basic knowledge of PHP, SQL, and HTML. This tutorial assumes you are
    using MySQL, adjust accordingly for a different DBMS. First off lets define the database table
    where our users will be stored. Using phpMyAdmin run this statement to create our table....

    1. Looking for simple, register, script, simple, register, script

Searching Video's for simple, register, script, simple, register, script
advertisement




A Simple Register Script - This Is a Very Simple Register-Script



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE