1

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");
  }
}

enter image description here

2 Answers 2

1

I think you need to change form's attribute "type" to "method". Your code after: <form action="includes/update.inc.php" method="post">

Sign up to request clarification or add additional context in comments.

Comments

0

First, you make sure that your value is correctly transported into the backend section.

<?php
  include 'dbh.inc.php';

if (isset($_POST['submit-edit'])) {

  $id = $_POST['editId'];
  $editContent = $_POST['editContent']; echo $editContent; //Verification step

  /*$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");
  }*/
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.