update and delete record in php and mysql
Delete Record:
<html>
<head>
</head>
<body>
<table border="1" align="center">
<tr>
<td>Id</td><td>Name</td><td>Delete</td><td>Update</td>
</tr>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test");
if(isset($_GET['id']))
{
mysql_query("delete from stud where id=".$_GET['id']."");
?>
<script language="JavaScript">
window.location="dispaly.php";
</script>
<?php
}
$sql="select * from stud";
$qsql=mysql_query($sql);
while($row=mysql_fetch_array($qsql))
{
?>
<tr>
<td><?php echo $row[0]; ?></td>
<td><?php echo $row[1]; ?></td>
<td><a href="dispaly.php?id=<?php echo $row[0]; ?>">Delete</a></td>
<td><a href="update.php?uid=<?php echo $row[0]; ?>">Update</a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
update.php
<html>
<head>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test");
if(isset($_POST['submit']))
{
$sql="update stud set name='".$_POST['txtnm']."',city='".$_POST['txtct']."' where id=".$_GET['uid']."";
mysql_query($sql);
?>
<?php
}
$sql="select * from stud where id=".$_GET['uid']."";
$qsql=mysql_query($sql);
$row=mysql_fetch_array($qsql)
?>
<form method="post">
<table border="1" align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="txtnm" value="<?php echo $row['1']; ?>"></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="txtct" value="<?php echo $row['2']; ?>"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Update"></td>
<td><input type="reset" name="reset" value="Cancle"></td>
</tr>
</table>
</form>
</body>
</html>
<head>
</head>
<body>
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("test");
if(isset($_POST['submit']))
{
$sql="update stud set name='".$_POST['txtnm']."',city='".$_POST['txtct']."' where id=".$_GET['uid']."";
mysql_query($sql);
?>
<?php
}
$sql="select * from stud where id=".$_GET['uid']."";
$qsql=mysql_query($sql);
$row=mysql_fetch_array($qsql)
?>
<form method="post">
<table border="1" align="center">
<tr>
<td>Name:</td>
<td><input type="text" name="txtnm" value="<?php echo $row['1']; ?>"></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" name="txtct" value="<?php echo $row['2']; ?>"></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Update"></td>
<td><input type="reset" name="reset" value="Cancle"></td>
</tr>
</table>
</form>
</body>
</html>
-->Main Page:
--->Update Page
demo of update and delete record in php and mysql