PHP Registration Form-Part 2

This post is the continuation of the php registration form part1. As a quick reminder i just discussed the html layout of the registration page in part 1,so we now continue with the registration form.

After Designed the HTML page i already mentioned about the action attribute in the form tag in the first part, so now we are going to create a php page called update.php so update.php is something like a redirected page will shows some message so that data will be inserted in database.

Now we are going to create a database, As my suggestion is to use wamp,mamp ,lamp server for all php program execution which is a combo of apache, mysql and php.This three things are very essentially needed to run a php program. when u installed wamp server then run it and a small icon will show in the sytem tray so click it and go to phpmyadmin. so create a database name there of your choice.Now we are going to create a table in the database so that can be done by two methods one by coding method and the other one is creating a table with UI in Phpmyadmin so i go with the second one create a table and create the fields in the table so we need only 5 fields. all the fields are characters so choose the varchar datatype for all the field names and set  nonull for all fields so that some character will be enter in it and the most important one is to enter the length of the fields

So the table structure will be like in that above picture if you done that means database design is done now. 50% of the work is Completed.

Maybe you never forget the update.php.Yeah next now i’m going to that only so what we going to do in that is inserting the values of  fields entered  in the registration.html.

Below is the code  to insert the values into database


mysql_connect(“localhost”,”root”,””)or die(‘Error:’.mysql_error());
$query=”insert into user_details( first_name,last_name,Email,Password,Contact_no) values(‘”.$fname.”‘,'”.$lname.”‘,'”.$email.”‘,'”.$password.”‘,'”.$contactno.”‘)”;
mysql_query($query) or die(“Error updating database”);
echo “data successfully updated in database”;

i already said about the php delimiters<?php……..?>

$fname-Variable In php variables are declared by means of using $symbols in front of variable name

Here i’m using variables bcoz not to confuse with the values i get from the previous form

$_POST[‘fname’]- where post is the method we used in the previoushtml file so fname is the name of that text field so i’m getting the values of the field with the above post method call and i stored values in some other variable that should be used in the insert query.

So as i did for all the above fields.

now we are going to see some common connection strings that are used in php. first one  [mysql_connect] which is used to connect the database with the php file(“hostname”,”username”,”password”) we have to fill host, user and pass details in mysql_connect statement Host and user name will must entered in that syntax the default username is root. or statement is executed if it doesnt connect to the database

[mysql_select_db]- is the statement that uses to select the database name so you have to enter the database name in it.

[mysql_query]-is the query execution statement so you can write the query inside the statement as well

synatax for insert query is

INSERT into table name (field name of the table) values (field entered is the one that we get from the variables in the code described above)

echo statement is the most popular term in php where it should be used to display the thing that available in it. so whatever you entered in it will be displayed in the output. so now you done with the inserting fields in the database.

one most important thing that i missed in it was the validation now itself whatever you entered in textbox that will be stored in database even no values are also can be stored in it. so we will learn about that in part 3 of the registration form.

Feel free to ask doubts


Working For Cause Not For Applause

Tagged with: , , , , , , ,
Posted in PHP, web

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: