Lab12 PHP Update
Lab12 PHP Update
Lab # 12
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.
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.
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:
Insert.php
<?php
if(!empty($_POST))
{
$uname = $_POST['uname'];
$pwd = $_POST['pswd'];
$db_user = 'root';
$db_pass = "";
$db = 'test';//test
$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"> </td>
</tr>
<tr>
<td><em><strong>Password</strong></em></td>
<td><em><strong>
<input type="password" name="pswd" id="pswd" />
</strong></em></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><em><strong></strong></em></td>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</table>
</form>
BROWSER OUTPUT:
Objective # 3:
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:
DATABASE TABLE:
DELETION: