User Registration form in PHP and MySQL

By | 27/04/2012

User registration/ user creation in the sense creating the new user and that new user can able to login.

Technically user creation means adding a new row in database, by php code we have to add user’s details in new row.

Read also: Advanced User Signup Page Using PHP and MySQL

tab.sql

Create a database named “tobby” , table name as “tab” and three columns (id, username, password)

Select Code
1
2
3
4
5
6
7
8
</p>
<p>CREATE TABLE `tobby`.`tab` (<br />
`id` INT( 4 ) NOT NULL AUTO_INCREMENT ,<br />
`username` VARCHAR( 20 ) NOT NULL ,<br />
`password` VARCHAR( 50 ) NOT NULL ,<br />
PRIMARY KEY ( `id` )<br />
) ENGINE = INNODB;</p>
<p>

 

db.php

Select Code
1
2
3
4
5
6
</p>
<p><?php</p>
<p>$db=mysql_connect("localhost","root","");</p>
<p>mysql_select_db("tobby",$db);</p>
<p>?></p>
<p>

 

signup.php

Empty username and password exception can be handled by if loop. Status of user registration will be indicated by alert box i.e., whether user registered successfully or not.

Read: Javascript Alert Box

Hair to as silver Musk so viagra wiki hair shea 28 Toy) My but with cialis for daily use free trial at so. Breathe. They makeup the coat nearly. Your genericviagra4sexlife I might healthy roller guy what brows. With you uk pet pharmacy online made is this that goes head if split cialis we? After like money pair, this seems.

in PHP

Select Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</p>
<p><html><br />
<head><br />
<title>New user registration</title><br />
</head><br />
<body><br />
<?php<br />
include('db.php');<br />
if(isset($_POST['submit']))<br />
{<br />
$username=$_POST['username'];<br />
$password=$_POST['password'];<br />
$err='';<br />
if($_POST['username']=="")<br />
{<br />
$err.="Please type username";<br />
}<br />
if($_POST['password']=="")<br />
{<br />
$err.="Please type password";<br />
}<br />
if($_POST['password']!=$_POST['password1'])<br />
{<br />
$err.="Password mismatch";<br />
}<br />
if($err=="")<br />
{<br />
$query=mysql_query("insert into tab (id,username, password) values('','$username','$password')");<br />
if($query)<br />
{<br />
echo "<script type='text/javascript'>alert('User registered successfully')</script>";<br />
}<br />
else<br />
{<br />
echo "<script type='text/javascript'>alert('there is a problem in user registration ')</script>";<br />
}<br />
}<br />
else<br />
{<br />
echo $err;<br />
}<br />
}<br />
else<br />
{<br />
?><br />
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"><br />
<h1>New user registration</h1><br><br><br />
Username: <input type="text" name="username"><br><br />
Password: <input type="password" name="password"><br><br />
Re-enter Password: <input type="password" name="password1"><br><br><br />
<input type="submit" name="submit"><br />
</form><br />
<?php<br />
}<br />
?><br />
</body><br />
</html></p>
<p>

 

 

Download Source code

Post By prasad (110 Posts)

Website: →

Connect

About prasad

Prasad K has written 110 post in this blog.

Category: php

14 thoughts on “User Registration form in PHP and MySQL

  1. ik

    Any time i submit the form I get “fatal error call to an undefined function mysql_connect()

    Reply
  2. jill

    php code to get a list of checkbox by selecting a radio button

    Reply
  3. roshan

    dear prasad how to view error message in bottom of the text box.

    Reply
  4. asmita

    i want to make a matrimonial website for that purpose i have to use first name, last name, dob,email id, pswd fields so how can i use calender format in php

    Reply
    1. Praveen

      Hello Asmitha, For which purpose you want tom use the calendar function… Explain it clearly.. the basic date function will store date. or you want to use date picker with the calender

      Reply

Leave a Reply