PHP Registration Form-Part 5

Hi guys

Here is the continuation of the last part of the Registration form in php.More Importantly this is the fifth and last part of the tutorial okay will proceed to our tutorial, In the final part i discussed about the admin section for the registration form where you can able to view the datas available in the database.Here i’m going to explain About the edit and delete function of the data from the admin section.

In the last part the edit and delete links are created in the view table

echo “<td><a href=’edit.php?em=”.$row[‘Email’].”‘>” . edit . “</a></td>”;
echo “<td><a href=’delete.php?em=”.$row[‘Email’].”‘>” . Delete . “</a></td>”;

As you can see in the above code so we require two more php pages for that so create edit and delete php pages.Here i’m using mail field to select the record so mail field is must be filled.suppose if your doing without validation better to use id field. where em is simply a name or variable to get the mail record.

Now going to the edit.php Here we are going to modify the record so the first step is to display the data from the record and then values are modified finally it should be saved with the modified values.

if (isset($_POST[‘fname’]))


mysql_connect(“localhost”,”root”,””)or die(‘Error:’.mysql_error());
$query=”update user_details SET first_name = ‘”.$fname.”‘,last_name = ‘”.$lname.”‘,Email='”.$email.”‘,Password = ‘”.$password.”‘,Contact_no='”.$contactno.”‘ where Email='”.$email.”‘”;
mysql_query($query) or die(“Error updating database”);
echo “updated”;
mysql_connect(“localhost”,”root”,””)or die(‘Error:’.mysql_error());
$res=”select * from user_details where email='”.$_GET[’em’].”‘”;
while($result = mysql_fetch_array($row1)){
$re= $result[‘first_name’] ;
$wr= $result[‘last_name’];
$mail= $result[‘Email’];
$pass= $result[‘Password’];

$cont= $result[‘Contact_no’];



<script language=”JavaScript” type=”text/javascript”>
function checkform (form1)
var fname = form1.fname.value;
var email =;
var pass = form1.password.value;
var lname = form1.lname.value;
var contact = form1.contactno.value;
if (email == “”) {
alert( “Please enter your email address.” );;
return false ;
if (pass == “”){
alert(“Please Enter Your Password.”);
return false;
if (fname == “”){
alert(“Please Enter Your First Name”);
return false;
if (lname == “”)
alert(“Please enter Your Last Name”);
return false;
if (contact == “”)
alert(“Please enter the contact no”);
return false;
return true ;
<title>Edit this Page</title>

<form name=”form1″ method=”post” action=”edit.php?em=namah” onsubmit=” return checkform (form1);”>
<table cellspacing=”5″ cellpadding=”3″ width=”400″>
<td> First Name</td>
<td><input type=”text” name=”fname” value=”<?php echo $re;?>”/></td>
<td> Last Name</td>
<td><input type=”text” name=”lname” value=”<?php echo $wr; ?>” /></td>
<td> EMAIL</td>
<td><input type=”text” name=”email” value=”<?php echo $mail; ?>” /></td>
<td><input type=”password” name=”password” value=”<?php echo $pass;?>”  /></td>
<td> Contact No</td>
<td><input type=”text” name=”contactno” maxlength=”11″ size=”20″ value=”<?php echo $cont;?>”  /></td>
<td><input type=”Submit” name=”Ok” value=”okay” /></td>

You can see the above code  where we have to use select query first  and then use the update query. The lower section of the code contains full html where we used in the html page so thats pretty easy to do that. After that we are using variables for query Syntax for update query is

update table name  set  field= values;

Here in the select query we used to get the particular field by using where clauseyou can see in the below code

$res=”select * from user_details where email='”.$_GET[’em’].”‘”; where em is the name passed in the href tag in the view.php

Now i’m getting the modified values of field from the above select query so that  im getting that values in variables by the while loop thats it now i’m going to use that variable declared in the input field values between the php delimiters.

so that the values will be present when you click the edit link in the view.php after that you modify values and click submit it executes the update query so now the record will be updated with the modified values


Now i’m going to explain about the delete link in view.php where it also using to get the record by the mail field from the database.

mysql_connect(“localhost”,”root”,””)or die(‘Error:’.mysql_error());
$result=”DELETE FROM user_details WHERE email='”.$_GET[’em’].”‘”;
echo “successfully the record deleted”;

Delete query Syntax is: Delete from table name where field=value;

Finally an echo statement will be executed to indicate the record is deleted .you can use the connection statement to the database in a separate file and include that in every file so that will reduce your time by coding those two lines in every file.It will be very useful when you are doing big projects in php.

Syntax : include “filename”;

you can check that in view.php so that the particular record will be deleted from the database thats it guys you created a registration page now.Will See you in Next PHP Tutorial.


Working For Cause Not For Applause

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: