PHP tutorials,a way to getting some thing new in web

Followers

Powered by Blogger.

Tuesday 31 March 2015

Simple Registration using PHP

2 comments :
Hello Friends, As we have went through many topics like login,login with facebook,login with google,sms sending api,ffmpeg.But each and every website needs user to register on their website.they want user to be in touch with their website all time.Also they store data of user on website.For that one process is necessary which is known as registration.
All language like .NET,PHP,JAVA has codes to do registration.Even wordpress,drupal also do same.

But as PHP developer and being writing PHP codes,here i need to explain you how registration works and how code is implement.

First of all i will explain you process for same.


  • User come for visit on you website and signup for registration.
  • When he goes on registration page,he fills simple information form on your site and submit it.
  • All information which he inputs,they get stored into database.



Let's See this process in form of code:

HTML to create Form

index.php

<html>
<body>
<form action="" method="POST" name="form1" id="form1">
<label>Name:</label>
<input type="text" id="your_name" name="your_name" value=""/>
<label>User Name:</label>
<input type="text" id="user_name" name="user_name" value=""/>
<label>Password:</label>
<input type="text" id="pass" name="pass" value=""/>
<label>Confirm Password:</label>
<input type="text" id="c_pass" name="c_pass" value=""/>
<input type="submit" id="submit" name="submit" value="Submit"/>
</form>
</body>
</html>

PHP Code to store information:

 index.php

paste this code upside of html in same file.

<?php
include('connect.php');
if(isset($_POST['submit']))
{
$your_name=$_POST['your_name'];
$user_name=$_POST['user_name'];
$pass=$_POST['pass'];
$insert="INSERT INTO users SET name='".$your_name."',user_name='".$user_name."',password='".$pass."'";
$res=mysql_query($insert) or die(mysql_error());
$id=mysql_insert_id();
if($id > 0)
{
header('location:index.php?msg=1');
}
else
{
header('location:index.php?msg=2');
}
}
?>
 connect.php

<?php
$host="your_host_name";
$username="your_username";
$password="your_password";
$db="your_db_name";
$link=mysql_connect($host,$username,$password);
mysql_select_db($db,$link);
?>

Create database and make one table named "user" with fields username,password,name and other fields which you want from user to get stored.

run code...!!

2 comments :