0% found this document useful (0 votes)
4 views

Lab12 PHP Update

This document outlines Lab #12 for web development, focusing on inserting and deleting records in a MySQL database using PHP. It provides theoretical background on server-side scripting, along with practical PHP code examples for inserting and deleting user records. The lab also includes an exercise to design a login form and manipulate database records using Dreamweaver and phpMyAdmin.

Uploaded by

Shaheer Zaeem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lab12 PHP Update

This document outlines Lab #12 for web development, focusing on inserting and deleting records in a MySQL database using PHP. It provides theoretical background on server-side scripting, along with practical PHP code examples for inserting and deleting user records. The lab also includes an exercise to design a login form and manipulate database records using Dreamweaver and phpMyAdmin.

Uploaded by

Shaheer Zaeem
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab#12: Web Development – Insert & Delete Record SSUET/QR/114

Lab # 12

Objective: Use Dreamweaver Web Development tool to Insert/Delete Record.


1) To understand the concept of inserting in and deleting records from database.
2) To insert record in MySQL database using PHP.
3) To delete record from MySQL database.

Theory:
This lab is mainly concerned with the learning of the concept of Server Side Scripting in PHP and
to get aware of the concept of INSERTING & DELETING RECORDS in PHP. In this lab we are
actually implementing the functionality of insertion and deletion of records using PHP.

Objective #1:
To understand the concept of inserting in and deleting records from database.

Inserting Records in Database:

The INSERT INTO statement is used to insert new records in a table. It is possible to write the
INSERT INTO statement in two forms. The first form does not specify the column names where
the data will be inserted, only their values. The second form specifies both the column names and
the values to be inserted.

Deleting Records from Database:

The DELETE statement is used to delete rows in a table. It is possible to delete all rows in a table
without deleting the table. This means that the table structure, attributes, and indexes will be
intact.

Objective #2:

To insert record in MySQL database using PHP

PHP code for inserting record is as follows:

Insert.php

<?php
if(!empty($_POST))
{
$uname = $_POST['uname'];

$pwd = $_POST['pswd'];

CE-202L: Software Engineering Lab 88


Lab#12: Web Development – Insert & Delete Record SSUET/QR/114

$db_user = 'root';
$db_pass = "";
$db = 'test';//test

$con = mysqli_connect('localhost',$db_user,$db_pass) or die('Unable to connect database');

mysqli_select_db($con,$db)or die("cannot connect database practice");

$sql="insert into login(uname,pwd) values('".$uname."','".$pwd."')";

$result=mysqli_query($con, $sql);

if($result)
{
echo "You have successfully created new account";
}
else{
echo "Operation Failure please re-attempt";
}

}
?>
<form id="insert_form" name="insert_form" method="post" action="">
<table width="285" border="1">
<tr>
<th colspan="3" scope="col"><em><strong>Insert User Record</strong></em></th>
</tr>
<tr>
<td width="78"><em><strong>Username</strong></em></td>
<td width="144"><em><strong>
<input type="text" name="uname" id="uname" />
</strong></em></td>
<td width="22">&nbsp;</td>
</tr>
<tr>
<td><em><strong>Password</strong></em></td>
<td><em><strong>
<input type="password" name="pswd" id="pswd" />
</strong></em></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><em><strong></strong></em></td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</table>
</form>

CE-202L: Software Engineering Lab 89


Lab#12: Web Development – Insert & Delete Record SSUET/QR/114

BROWSER OUTPUT:

Objective # 3:

To delete record from MySQL database.

PHP code for deleting record is as follows:

Delete.php
<?php
session_start();
$uname = $_SESSION['usern'] ;
$db_user = 'root';
$db_pass = "";
$db = 'test';//test
$conn = mysqli_connect('localhost',$db_user,$db_pass) or die('Unable to connect database');
mysqli_select_db($conn,$db)or die("cannot connect database practice");
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$sql="Delete from login where uname = '".$uname."' ";
$result=mysqli_query($conn,$sql);
if($result)
echo "You have successfully deleted your account";
else
echo "Operation Failure please re-attempt";
?>
Exercise:
BROWSER OUTPUT:

Running it on the browser with the link


http://localhost/test/
Design a login form using Dreamweaver, database using phpMyAdmin and add 2 more
records and delete first 3 records and show the resultant table.

CE-202L: Software Engineering Lab 90


Lab#12: Web Development – Insert & Delete Record SSUET/QR/114

DATABASE TABLE:

DATABASE TABLE AFTER INSERTION:

DELETION:

CE-202L: Software Engineering Lab 91

You might also like