I am writing a code in php to update a table.
<form action="" method="POST">
<td><div align="center"><input type="text" name="id" value="<?php echo $Result['id']; ?>" readonly /></div></td>
<td><div align="center"><input type="text" name="studentid" value="<?php echo $Result['studentid']; ?>" /></div></td>
<td><div align="center"><input type="text" name="subjectid" value="<?php echo $Result['subjectid']; ?>" /></div></td>
<td><div align="center"><input type="text" name="marks" value="<?php echo $Result['marks']; ?>" /></div></td>
<td><div align="center"><input type="text" name="term" value="<?php echo $Result['term']; ?>" /></div></td>
<td><div align="center"><input type="text" name="year" value="<?php echo $Result['year']; ?>" /></div></td>
<td><div align="center"><input type="text" name="rank" value="<?php echo $Result['rank']; ?>" /></div></td>
<td><input type="submit" name="save" value="Save" /></td>
<td><input type="submit" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';" /></td>
<td></td>
</form>
The error I am having is that it posts the value it received and not the changed one (Changed while editing on the page)
This is your edit page from where you can update you data . i have used my database connect firstly you have to change database and table name.
And you should pass id
of that row in form of query string like edit.php?id=12
.
<?php
mysql_connect("localhost","root","root");
mysql_select_db("test");
$id=$_GET['id'];
if(isset($_POST['save']))
{
$id=$_POST['id'];
$st_id=$_POST['studentid'];
$sub_id=$_POST['subjectid'];
$marks=$_POST['marks'];
$term=$_POST['term'];
$year=$_POST['year'];
$rank=$_POST['rank'];
$sql="UPDATE `test`.`user` SET `st_id` = '$st_id',
`sub_id` = '$sub_id',
`mark` = '$marks',
`term` = '$term',
`year` = '$year',
`rank` = '$rank' WHERE `user`.`id` =`$id`";
mysql_query($sql);
}
$result=mysql_query("select * from user where id=$id");
$Result=mysql_fetch_array($result);
?>
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
</html>
<form action="" method="POST">
<td><div align="center"><input type="text" name="id" value="<?php echo $Result['id']; ?>" readonly /></div></td>
<td><div align="center"><input type="text" name="studentid" value="<?php echo $Result['st_id']; ?>" /></div></td>
<td><div align="center"><input type="text" name="subjectid" value="<?php echo $Result['sub_id']; ?>" /></div></td>
<td><div align="center"><input type="text" name="marks" value="<?php echo $Result['mark']; ?>" /></div></td>
<td><div align="center"><input type="text" name="term" value="<?php echo $Result['term']; ?>" /></div></td>
<td><div align="center"><input type="text" name="year" value="<?php echo $Result['year']; ?>" /></div></td>
<td><div align="center"><input type="text" name="rank" value="<?php echo $Result['rank']; ?>" /></div></td>
<td><input type="submit" name="save" value="Save" /></td>
<td><input type="submit" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';" /></td>
<td></td>
</form>
</body>
</html>