You are on page 1of 2

<html><!-- 13A.

PHP -->
<head><title>Search Result </title></head>
<body style="text-align:center;">
<hr>

<h3>Want to insert some more data to database...</h3>


<form action="13.html" method="post" />
<input type="submit" value="insert data">
</form>
<hr>

<?php
$dbh = mysql_connect('localhost', 'root','') or die(mysql_error());
mysql_select_db('test') or die(mysql_error());
$nme = $_POST['name'];
$ad1 = $_POST['add1'];
$ad2 = $_POST['add2'];
$eml = $_POST['email'];
$search_key=$_POST["search_name"];
$hidden_value = $_POST['hi'];

if($hidden_value =='hidd')
{
if($nme != "" && $ad1 != "")
{
$query = "INSERT INTO stud VALUES('$nme', '$ad1', '$ad2', '$eml')";
$result = mysql_query($query) or die(mysql_error());
echo "<h3>Want to search some data from existing data..</h3>";
echo "<form action='13a.php' method=post>";
echo "Enter Name of the person <input type='text' name='search_name'>
";
echo "<input type=submit>";
echo "</form>";
echo "<hr>";
echo "<h2 style='color:blue;'>\n Data sucessfully inserted </h2>";
}
else
echo "<h2 style='color:red;'>\n one of the field is empty </h2>";
}
else
{
if(!isset($_POST['search_name']))
{
echo "<h3>Want to search some data from existing data..</h3>";
echo "<form action='13a.php' method=post>";
echo "Enter Name of the person <input type='text' name='search_name'
>";
echo "<input type=submit>";
echo "</form>";
echo "<hr>";
}
else
{
echo "<h3>Want to search some data from existing data..</h3>";
echo "<form action='13a.php' method=post>";
echo "Enter Name of the person <input type='text' name='search_name'
>";
echo "<input type=submit>";
echo "</form>";
echo "<hr>";
$search_key1=$_POST[ search_name ];
if($search_key1==null)
{
echo "<h2 style='color:red;'>\n No name is entered for search </h
2>";
}
else
{
echo "Entered Name is $search_key1 \n";
$var=mysql_query("SELECT * FROM stud WHERE name like '%$search_key
1%'");
echo"<table border size=1 align=center>";
echo"<tr><th>Name</th> <th>Address 1</th> <th>Address 2</th><th>E
-mail</th></tr>";
while ($arr=mysql_fetch_row($var))
{
echo "<tr><td>$arr[0]</td> <td>$arr[1]</td> <td>$arr[2]</td><t
d>$arr[3]</td> </tr>";
}
}
}
}
mysql_close($dbh);
?>
</body>
</html>

You might also like