Creating a Sample Form that can Search and Delete Data
SAMPLE
DISPLAY.PHP
<?php
$id = $_POST['id'];
$fn = $_POST['fn'];
$ln = $_POST['ln'];
$con=mysql_connect('localhost','root','');
mysql_select_db('db_sep1',$con);
mysql_query("INSERT INTO sep
values('$id','$fn','$ln');");
echo
" INFO INSERTED";
?>
SEARCH.PHP
<?php
$search=$_POST['id'];
$server=
"localhost";
$user="root";
$pass="";
$db
= 'db_sep1';
$tbl
= 'sep';
mysql_connect("localhost","root","");
mysql_select_db('db_sep1')
or die ("Cant connect database");
if
(!mysql_select_db($db)) die ("Cant open database");
$result
= mysql_query("SELECT * FROM {$tbl} where IdNo ='$search'");
$field_num
= mysql_num_fields($result);
echo"{$tbl}";
echo
"<table border ='1'><tr>";
for($i
= 0; $i<$fields_num; $i++)
{
$field
= mysql_fetch_field($result);
echo
"<td size = '2'><b>$field>Name</td>";
}
echo
"<tr>\n";
while
($row = mysql_fetch_row($result))
{
echo
"<tr>";
foreach($row
as $cell)
echo "<td> $cell
</td>";
echo "</tr>\n";
}
echo "</table>";
?>
DELETE.PHP
<?php
$delete=$_POST['id'];
$server=
"localhost";
$user="root";
$pass="";
$db
= 'db_sep1';
$tbl
= 'sep';
mysql_connect("localhost","root","");
mysql_select_db('db_sep1')
or die ("Cant connect database");
if
(!mysql_select_db($db)) die ("Cant open database");
$result
= mysql_query("DELETE FROM {$tbl} where IdNo ='$delete'");
$code="Delete
$delete";
$qery=mysql_query($code);
if(!qury)
echo mysql_error();
else
echo "Data deleted
successfully.";
?>
DEMO
:
Let’s fill
up each field in the FORM.
And SUBMIT.
And it will
take us to another page.
Where it
will inform us that the information we’ve
entered is successfully inserted in the
DATABASE.
Through
using DISPLAY.PHP.
And it
would appear like this.
To check if
the info we’ve inputted is already inserted.
Let’s Go to
CMD.
So, there
it goes.
Now, in the
form itself let’s try to search the ID Number of the information we’ve
inserted.
By using, SEARCH.PHP.
Let’s click
SEARCH.
There it goes.
Now, Let’s
try to DELETE the info we’ve inserted by inputting its ID Number.
Here, We
are using DELETE.PHP.
And DELETE.
And it will
take you again to another page.
Saying ..
Now, Let’s
go to CMD again and check if the info is deleted.
YES! The
info is already deleted.
THANKSS!!










Comments
Post a Comment