User Registration Using PHP MySQL

By | August 8, 2012

user registration using php mysql is an important concept for newbie programmer, user details like username, password, gender of the user and email address will be asked. After user provided their details, in this index.php itself database updation will be takes place and notification about registration will be shown alert box.

[code type=html]

CREATE TABLE `freeze`.`tb` (
`id` INT( 3 ) NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 20 ) NOT NULL ,
`password` VARCHAR( 20 ) NOT NULL ,
`gender` VARCHAR( 6 ) NOT NULL ,
`email` VARCHAR( 20 ) NOT NULL ,
PRIMARY KEY ( `id` )

) ENGINE = INNODB;

[/code]

 

index.php

After submitting the values,  control  comes to this loop if(isset($_POST[‘submit’])) this loop will allow only when we click submit button and all values are stored in a variable. The stored variable values are added to the database.

[code type=php]

<?php
$query=mysql_connect(‘localhost’,’root’,”);
mysql_select_db(“freeze”,$query);
if(isset($_POST[‘submit’]))
{
$username=$_POST[‘username’];
$password=$_POST[‘password’];
$gender=$_POST[‘gender’];
$email=$_POST[’email’];
$query1=mysql_query(“insert into tb values(”,’$username’,’$password’,’$gender’,’$email’)”);

if($query)
{
echo “user regsitration successful  “;
}
else
{
echo “There is a problem in user registration, Please try again “;
}
}
?>
<fieldset style=”width:275px;”>
<h1>User Registration / Signup</h1>
<form method=”post” action=”index.php”>
Username: <input id=”tb” type=”text” name=”username” /><br>
Password: <input id=”tb” type=”password” name=”password” /><br>
Re-Password: <input id=”tb” type=”password” name=”password1″ /><br>
Gender
<input type=”radio” name=”gender” value=”male” />Male
<input type=”radio” name=”gender” value=”female” />Female<br>
Email: <input id=”tb” type=”text” name=”email” /><br><br>
<input type=”submit” name=”submit”>
</form>
</fieldset>
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *