I'm using a SELECT query to generate a html table (screenshot) which displays data from a sql table.
Every <tr> is generating an additional <tr> for the administrator (if ($userUid == "admin") {) with the sql entry's ID + <textarea> to edit the content in the SQL column public.
The second administrator <tr> includes a <form> element to edit the content. I assume the repeating name elements of the multiple <input>s / <button>s in the form element cause the problem, but the script action="includes/update.inc.php" just returns a blank page with the following URL and no php error:
http://localhost:10006/includes/update.inc.php?editId=18&editContent=adsasd&submit-edit=
Generated table:
<?php
<table> ... / table head...
foreach($result as $row) {
echo "<tr class='data-row'>";
echo "<td>".$date_form."</td>
echo "<td>".$time_form."</td>
echo "<td>".$subject_form."</td>
echo "<td>".$private."</td>
echo "<td>".$public."</td>
echo "<td>".$date_form."</td>
echo "</tr>";
if ($userUid == "admin") { ?>
<tr class='admin-row'>
<form action="includes/update.inc.php" type="post">
<td><input name="editId" type="text" value="<?php echo $Id; ?>"></td>
<td class='p-2' colspan="4">
<textarea name="editContent" class="content-update-textarea" type="text"></textarea>
</td>
<td><button name="submit-edit" type="submit">EDIT</button></td>
</form>
</tr>
<?php }}?>
</table>
This is the /includes/update.inc.php script called by the form element which is supposed to update the content using <textarea name="editContent"> of the SQL row with the ID: <input name='editId'>.
<?php
include 'dbh.inc.php';
if (isset($_POST['submit-edit'])) {
$id = $_POST['editId'];
$editContent = $_POST['editContent'];
$sql = "UPDATE lesson SET public = ? WHERE id = ?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "Failed to prepare statement.";
exit();
} else {
mysqli_stmt_bind_param($stmt, "ss", $editContent, $id);
mysqli_stmt_execute($stmt);
header ("Location: ../lesson.php?update=success");
}
}
