Home > Software design >  PHP/HTML table row not changing to form on pressing update button
PHP/HTML table row not changing to form on pressing update button

Time:10-12

I am trying to make a table where data from a database is shown and by pressing on the update button the (not the 'lidnummer one')cells on the row should change to a form input field with the data from that row as the initial input values. table image

I've copied the idea from something I found and changed it to fit all the data I want to show, but I can't get the row to change upon pressing the 'update' button.

echo '<tr>';
echo '<td>Lidnummer</td>';
echo '<td>Voornaam</td>';
echo '<td>Achternaam</td>';
echo '<td>Huisnummer</td>';
echo '<td>Adres</td>';
echo '<td>E-mailadres(sen)</td>';
echo '<td>Telefoonnummer(s)</td>';
echo '<td>Update</td>';
echo '<td>Delete</td>';
echo '<tr>';
for ($j = 0 ; $j < $num_members ;   $j)
{ 
    $row = $select_result->fetch_array(MYSQLI_ASSOC);   
    
    echo '<tr>';
    if(isset($_GET['lidnummer']) && $row['lidnummer'] == $_GET['lidnummer'])
    {
        echo '<form action="includes/update_ledenlijst.php" method="POST">';
        echo '<td>' . $row["lidnummer"] . '</td>';
        echo '<td><input type="text" name="voornaam" value="' . $row['voornaam'] . '"></td>';
        echo '<td><input type="text" name="naam" value="' . $row['naam'] . '"></td>';
        echo '<td><input type="text" name="huisnummer" value="' . $row['huisnummer'] . '"></td>';
        echo '<td><select id="adres" name="adres">';
                include 'includes/select_postcodes.php';
        echo '</select>';
        echo "<td>";
        echo '<textarea>';
        toon_contactgegevens("telefoonnummers", $row, $conn, "telefoonnummer", "form_data");
        echo '</textarea>';
        echo '</td>';
        echo '<td>';
        echo '<textarea>';
        toon_contactgegevens('emails', $row, $conn, 'email', 'form_data');
        echo '</textarea>';
        echo '</td>';
        echo '<td><button type="submit" class="buttons">Save</button></td>';
        echo '<td>----</td>';
        echo '</form>';
    } else {           
        echo '<td>' . htmlspecialchars($row["lidnummer"])   . "</td>";
        echo '<td>' . htmlspecialchars($row["voornaam"])    . "</td>";
        echo '<td>' . htmlspecialchars($row["naam"])        . "</td>";
        echo '<td>' . htmlspecialchars($row["huisnummer"])  . "</td>";
        echo '<td>' . htmlspecialchars($row["adres"]) . ", " . htmlspecialchars($row["postcode"]) . " " .  htmlspecialchars($row["woonplaats"]) . '</td>';
        echo '<td>';
        toon_contactgegevens('emails', $row, $conn, 'email', "table_data");
        echo '</td>';
        echo '<td>'; 
        toon_contactgegevens("telefoonnummers", $row, $conn, "telefoonnummer", "table_data");
        echo '</td>';  
        echo '<td><a class="buttons" href="home_ledenlijst.php?id='.  $row["lidnummer"] . '" role="button">Update</a></td>';
                
    }
    echo "<td><a class='buttons' href='includes/delete_ledenlijst.php?id='" . $row['lidnummer'] . "' role='button'>Delete</a></td>"; 
    echo "</tr>";
}

This will probably be something I have overlooked and is really easy.. But I am new to this so I am still learning :)

CodePudding user response:

You're passing a value called id to the server:

href="home_ledenlijst.php?id='.  $row["lidnummer"] . '"

But looking for a value called lidnummer:

$_GET['lidnummer'] 

How you identify the values needs to be the same. Try looking for the id value:

$_GET['id'] 

CodePudding user response:

You are checking for $_GET['lidnummer'] but you are setting id='. $row["lidnummer"]

Change

id='.  $row["lidnummer"]

to

lidnummer='.  $row["lidnummer"]

Cheers! :)

=C=

  • Related