Insert Update Delete Search in php

index.php

<form name=”f1″ method=”post” action=”query.php”>
<table width=”305″ height=”198″ border=”1″>
<tr>
<td width=”112″>User Id</td>
<td width=”177″><input type=”text” id=”uid” name=”uid”></td>
</tr>
<tr>
<td width=”112″>Username</td>
<td width=”177″><input type=”text” id=”uname” name=”uname”></td>
</tr>
<tr>
<td>Password</td>
<td><input type=”password” id=”pass” name=”pass”></td>
</tr>
<td height=”45″ colspan=”3″ align=”center”><input type=”submit” value=”Insert” name=”insert”>
<input type=”submit” value=”Update” name=”update”>
<input type=”submit” value=”Delete” name=”delete”>
<input type=”submit” value=”Display All” name=”displayall”>
<a href=”search.php”>Search</a></td>
</tr>
</table>
</form>

Query.php

<?php
$cn=mysql_connect(“localhost:3306″,”root”,””);
mysql_select_db(“iuds”,$cn);

// ________________________I N S E R T__________________________________________

if(isset($_POST[“insert”]))
{
$uid=$_POST[‘uid’];
$uname=$_POST[‘uname’];
$pass=$_POST[‘pass’];

$q=”INSERT INTO udata values(‘$uid’,’$uname’,’$pass’)”;

mysql_query($q);
echo “INSERTed successfully”;

}

// _______________________________U P D A T E________________________________

if(isset($_POST[“update”]))
{
$uid=$_POST[“uid”];
$uname=$_POST[“uname”];
$pass=$_POST[“pass”];

$q=”UPDATE udata SET uname=’$uname’,pass=’$pass’ WHERE uid=’$uid'”;
mysql_query($q);
echo “UPDATEd successfully”;
}
// ________________________D E L A T E__________________________

if(isset($_POST[“delete”]))
{
$uid=$_POST[‘uid’];
$uname=$_POST[‘uname’];
$pass=$_POST[‘pass’];

$q=”DELETE FROM udata WHERE uid=”.$uid;
mysql_query($q);
echo “DELETEd successfully”;
}
// ___________________D I S P L A Y_________________________________

if(isset($_POST[‘displayall’]))
{
$uid=$_POST[‘uid’];
$uname=$_POST[‘uname’];
$pass=$_POST[‘pass’];

$q=”select * FROM udata”;
$r=mysql_query($q);

echo “<table border=1>”;
echo “<tr><td>User Id</td><td>User name</td><td>Password</td></tr>”;
while($row=mysql_fetch_array($r))
{
echo “<tr>
<td>$row[0]</td>
<td>$row[1]</td>
<td>$row[2]</td>
<td><a href=index.php?uid=$uid[0]>back</a></td>
</tr>”;
}
echo “</table>”;
}

// ____________________________S E A R C H D I S P L A Y____________________

$uid=””;
$uname=””;
$pass=””;
if(isset($_GET[‘uid’]))
{
$r=mysql_query(“select * from udata where uid=”.$_GET[‘uid’]);
while($row=mysql_fetch_array($r))
{
$no=$row[0];
$name=$row[1];
$marks1=$row[2];
}
}

?>

Search.php

<form method=”post”>
<table>
<tr>
<td>Search User By Id</td>
<td><input type=”text” name=”uid”></td>
<td><input type=”submit” value=”search” name=”search”></td>
</tr>
</table>
</form>
<?php

$cn=mysql_connect(“localhost”,”root”,””);
$db=mysql_select_db(“iuds”,$cn);

if(isset($_POST[“search”]))
{
$uid=$_POST[‘uid’];
$r=mysql_query(“select * from udata where uid=’$uid'”);
echo $r;

echo “<table border=1>”;
echo “<tr><td>User Id</td><td>User name</td><td>Password</td></tr>”;
while($row=mysql_fetch_array($r))
{
echo”<tr>
<td>$row[0]</td>
<td>$row[1]</td>
<td>$row[2]</td>
<td><a href=search.php?uid=$row[0]>select</a></td>
</tr>”;
}
}
echo “</table>”;
?>

Tagged:

Leave a comment