The page contains two updates for tabular data to update PHP + HTML

I am trying to make an edit function for my table (pulls from mysql). In a nutshell, how it works, when you click on the edit button, it turns the specific text into an input field. A save button appears next to the field. The problem I am having when I click the Save button reloads but the table data is not refreshed. I need to reload the page to update the table data. Here is my php / mysql embed 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:

    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>';

}

      

+3


source to share


1 answer


Make JSON from mysql table data and add data to table. After successful input / update, update your JSON.



0


source







All Articles