I am trying to make an edit function for my table (pulls from mysql). In a nutshell the way it works is when you click on an edit button it turns specific text into an input field. A save button also appears next to the field. The problem I'm having when you click on the 'save' button the page reloads but the table data does not update. I have to reload the page again for the table data to update. Here is my php/mysql insert code:
// DEFINING POST VARIABLES
$u_first = $_POST['U_firstname'];
$u_last = $_POST['U_lastname'];
$find_id = $_POST['sid'];
// QUERY DEFINING WHAT TO UPDATE
$query = "UPDATE studentdata SET firstname = ? , lastname = ? WHERE userid = ?";
// PREPARE STATEMENT
$statement = $mysqli->prepare($query);
//BIND parameters for markers
$results = $statement->bind_param('ssi', $u_first, $u_last, $find_id);
$statement->execute();
$statement->close();
I'm not sure if this matters but here is my table code too:
while($row = $query_results->fetch_array()) {
// CONVERTS FIRST & LAST NAME INTO A SINGLE VARIABLE
$NN_first = $row["firstname"];
$NN_last = substr($row["lastname"], 0, 1);
$NN_full = $NN_first.' '.$NN_last;
// PRINTING TABLE ROW
print '<tr>';
// MAKING FORM
print '<form action="example.php" method="POST">';
// GETS/MAKES HIDDEN USER ID
print '<input type="hidden" name="sid" value="'.$row["userid"].'">';
// PRINTS FULL NAME VARIABLE
print '<td>'.$NN_full.'</td>';
// PRINTS UPDATE BUTTON
print '
<td class="textcenter">
<input type="submit" class="example-page-btn" name="Update'.$row["userid"].'" value="Update">
<input type="submit" class="example-page-btn" name="Delete" value="Delete">
</td>';
// PRINTS FORM CLOSE
print '</form>';
// PRINTS END TABLE ROW
print '</tr>';
}
Make a JSON by your mysql table data and append the data in your table. After successful entry/update , update your JSON.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.