My code doesn't update the rows in my database, there is no syntax error, so it must be a logical error, it might be the positions of the braces. I want to update multiple columns in the same row. Here is the code -
<table border="1" align = "center" >
<form method="POST" action="testupdate.php">
<?php
while ($row=mysqli_fetch_assoc($q)){
?> <tr><td><input name="select2" type="radio" value="<?php echo $row['c_id']; ?>"></td>
<?php
echo "<td>".$row['c_id']."</td>";
echo "<td>".$row['no_computer']."</td>";
echo "<td>".$row['c_type']."</td>";
echo "<td>".$row['c_location']."</td></tr>";
}
?>
<input type="submit" name="update" value="update" ></table></form>
<form method="POST" action="testupdate.php">
<?php
if (isset($_POST['select2'])){
if (isset($_POST['update'])){
?>
<form method="POST" action="testupdate.php">
no of computers: <br /><input type="text" name="no_computer2"><br /><br />
type: <br /><input type="text" name="c_type2"><br /><br />
location: <br/><input type="text" name="c_location2"><br /><br />
technical status: <br /><input type="text" name="tech_status2"><br /><br />
<input type="submit" name="ok" value="okay">
</form>
<?php
if (isset($_POST['ok'])){
$nc2= $_POST['no_computer2'];
$ct2= $_POST['c_type2'];
$cl2= $_POST['c_location2'];
$ts2= $_POST['tech_status2'];
$i=$_POST['select2'];
$s2="UPDATE `tech_computer` SET `no_computer`='$nc2' , `c_type`='$ct2' , `c_location`='$cl2', `tech_status`='$ts2' where `c_id` like '$i'";
$q2=mysqli_query($s2);
header ('location:testupdate.php');
}}}
?>
$_POST
will contain the values which are present in the currentform
. When the second form get submitted the values of firstform
is overwritten. There is no field -select2
inside the secondform
. Try with adding ahidden
field with posted value as its value -