table.php
<?php
include('../connections/conn.php');
include('../php/login.php');
$sql = "SELECT * FROM person";
$records = mysqli_query($conn, $sql)
?>
<html>
<head>
<title>Table</title>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Salary</th>
</tr>
<?php
while($row = mysqli_fetch_array($records)){
$name = $row['Name'];
$age = $row['Age'];
$salary = $row['Salary'];
$id = $row['id'];
echo "<tr><form action=update.php method=post>";
echo "<td><input type=text name=pname value='$name'></td>";
echo "<td><input type=text name=age value='$age'></td>";
echo "<td><input type=text name=salary value='$salary'></td>";
echo "<input type=hidden name=id value='$id'></td>";
echo "<td><input type=submit>";
echo "</form></tr>";
}
?>
</table>
</body>
</html>
(this part of the code displays the table and its values)
Update.php
<?php
include('../connections/conn.php');
include('../php/login.php');
$sql = "UPDATE person SET
Name='$_POST[pname]',Age='$_POST[age]',Salary='$_POST[salary]' WHERE
id='$_POST[id]'";
if(mysqli_query($conn, $sql)){
header("refresh:1 url=table.php");
}
else{
echo"Not Update";
}
$records = mysqli_query($conn, $sql)
?>
(this part is for updating the table)
I have got the code to update the contents of a table using buttons however I would like to just have one button that will update the whole table. At the moment I use a button per row to update that particular row.