Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-08-2007, 04:08 PM
Senior Member
 
Join Date: May 2007
Posts: 181
Blog Entries: 1
skyfe is on a distinguished road
registration script

Oke, in this tutorial I'm going to explain how to make a registration system.

The register system
Oke, let's start with the database, we'll need a database where we'll put all accounts into. Import this SQL:
Quote:
CREATE TABLE `register` (
`id` int(5) NOT NULL auto_increment,
`username` varchar(40) NOT NULL,
`password` varchar(50) NOT NULL,
`email` varchar(35) NOT NULL,
`country` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
just put it into a .sql file and import it, or just goto 'SQL' and copy-past it. This will create the table register, were all account information after registrating, will be putting into. Let's start with making a form for the registration system. We let the user fill in the wanted username, password, email and country.

Quote:
<h4><b>REGISTER</h4></b>
<form method='POST' action='register.php'>
<b>username:</b> <input type='text' name='username'> <br>
<b>password:</b> <input type='password' name='password'> <br>
<b>confirm password:</b> <input type='password' name='password_confirm'> <br>
<b>email:</b> <input type='text' name='email'> <br>
<b>country:</b> <input type='text' name='country'> <p>
<input type='submit' value='register' name='submit'>
</form>
Easy, isn't it? Once the submit button is pressed, it will set all fields, filled in values, into $_POST['field_name']. We just let the user fill in the user info he wants, but now we have to check if the info he filled in is 'ok' and if he filled in everything correctly. We'll also check if the username not just already does exist.

Quote:
mysql_connect(localhost, root, password);
mysql_select_db(scripts);
if(isset($_POST['submit'])) {
if(!isset($_POST['username']) || empty($_POST['username']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['country']) || empty($_POST['country'])) {
echo "<font color='red'>Please fill in all fields!</font>";
}else{
if($_POST['password'] != $_POST['password_confirm']) {
echo "<font color='red'>Please confirm your password correctly!</font>";
}else{
$query = mysql_query("INSERT INTO register(username, password, email, country) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['country']."') ") or die("<font color='red'>Could not create your account, please contact the site web master!</font>");
echo "<font color='green'>You have succesfully been registrated! </font>";
}
}
}else{
//form here
}
oke, this is the full script which will check what is filled in, and if everything is correctly: it will insert it into the database (create the account). Oke, lets go trough the script.

Quote:
mysql_connect(localhost, root, password);
mysql_select_db(scripts);
this will connect to localhost, with username: root, en password: password, on database: scripts, change this to whatever login info you have on your (local)host.

Quote:
if(isset($_POST['submit'])) {
this part will check if the $_POST['submit'] does exist with the function: isset() if the var $_POST['submit'] DOES exist, the submit button have been pressed(caus once the user press on the button called 'submit', all input fields will be set into $_POST['field_name']).

Quote:
if(!isset($_POST['username']) || empty($_POST['username']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['country']) || empty($_POST['country'])) {
this part will check if the user didn't leave any fields empty, if he did, there will be an error message(by the follow script):
echo "<font color='red'>Please fill in all fields!</font>";

Quote:
}else{
if($_POST['password'] != $_POST['password_confirm']) {
echo "<font color='red'>Please confirm your password correctly!</font>";
but if everything is filled in(}else{) then it will check if the password is correctly confirmed, if the 2 passwords filled in, doesn't match, it will give again an error.

Quote:
}else{
$query = mysql_query("INSERT INTO register(username, password, email, country) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['country']."') ") or die("<font color='red'>Could not create your account, please contact the site web master!</font>");
echo "<font color='green'>You have succesfully been registrated! </font>";
but if everything is filled in correctly, then it will insert everything into the database, the table: register(fields: username, password, email and country) and the values that will be put into those fields will be the values that are filled in in the form.
Now let's put all together.

Quote:
<?php
mysql_connect(localhost, root, password);
mysql_select_db(scripts);
if(isset($_POST['submit'])) {
if(!isset($_POST['username']) || empty($_POST['username']) || !isset($_POST['password']) || empty($_POST['password']) || !isset($_POST['email']) || empty($_POST['email']) || !isset($_POST['country']) || empty($_POST['country'])) {
echo "<font color='red'>Please fill in all fields!</font>";
}else{
if($_POST['password'] != $_POST['password_confirm']) {
echo "<font color='red'>Please confirm your password correctly!</font>";
}else{
$query = mysql_query("INSERT INTO register(username, password, email, country) VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '".$_POST['country']."') ") or die("<font color='red'>Could not create your account, please contact the site web master!</font>");
echo "<font color='green'>You have succesfully been registrated! </font>";
}
}
}else{
?>
<h4><b>REGISTER</h4></b>
<form method='POST' action='testje.php'>
<b>username:</b> <input type='text' name='username'> <br>
<b>password:</b> <input type='password' name='password'> <br>
<b>confirm password:</b> <input type='password' name='password_confirm'> <br>
<b>email:</b> <input type='text' name='email'> <br>
<b>country:</b> <input type='text' name='country'> <p>
<input type='submit' value='register' name='submit'>
</form>
<?php
}
?>
and now we have our own registration script!
I hope you understanded it, caus it's hard for me to explain it in good English...
Well, anyways, enjoy ^^.

Attached Files
File Type: zip register.zip (688 Bytes, 93 views)

Last edited by skyfe; 06-08-2007 at 04:12 PM.
Reply With Quote
  #2 (permalink)  
Old 06-08-2007, 04:45 PM
Turbocharged_06's Avatar
VIP Member
 
Join Date: Mar 2007
Posts: 151
Turbocharged_06 is on a distinguished road
nice tutorial good job
__________________
OUTLAW-WEB.NET
Reply With Quote
  #3 (permalink)  
Old 06-09-2007, 09:18 PM
Junior Member
 
Join Date: Jun 2007
Posts: 20
sabje is on a distinguished road
omg thank you sooo much
Reply With Quote
  #4 (permalink)  
Old 06-10-2007, 06:34 PM
Junior Member
 
Join Date: Jun 2007
Posts: 20
DaRul0r is on a distinguished road
omg, i needed it so much... thanks a lot
Reply With Quote
  #5 (permalink)  
Old 06-11-2007, 11:30 AM
Junior Member
 
Join Date: Jun 2007
Posts: 20
darkthug is on a distinguished road
thnkx this is what im looking for a long time
Reply With Quote
  #6 (permalink)  
Old 06-13-2007, 11:41 PM
Junior Member
 
Join Date: Jun 2007
Posts: 21
4ran is on a distinguished road
Excellent!! Thanks a lot.. Useful tutorial
Reply With Quote
  #7 (permalink)  
Old 06-14-2007, 03:37 AM
Junior Member
 
Join Date: Mar 2007
Posts: 16
Kaldres is on a distinguished road
thx imma try this soon
Reply With Quote
  #8 (permalink)  
Old 06-16-2007, 10:56 AM
Junior Member
 
Join Date: Mar 2007
Posts: 19
Kasharas is on a distinguished road
cool script, thx
Reply With Quote
  #9 (permalink)  
Old 06-17-2007, 12:22 PM
Junior Member
 
Join Date: Jun 2007
Posts: 21
tecnologin is on a distinguished road
goog working thanks
Reply With Quote
  #10 (permalink)  
Old 06-19-2007, 11:04 AM
Junior Member
 
Join Date: Jan 2007
Posts: 20
decore is on a distinguished road
tnx dude Very helpful

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 10:46 PM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com