Home>

Thanks for your help.
Currently, I am creating a todo list as part of creating a portfolio for employment of engineers.
Therefore, the process of "Inserting the data sent in the form of html in the database and displaying it in the php file" does not work as desired, and I am in trouble.

I want to achieve

I want to display the data inserted in the database.

Applicable source code
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>todo list</title>
</head>
<body>
    todo list
  <form action="index.php" method="POST" nmae="form1">
  <p>Let's add something to do today!</p>
  <input type="text" name="todo_content"><br>
      <input type="submit" value="send"><br>
  </form>
</body>
</html>
<?php
require_once "DBconnect.php";
try {
    $pdo->beginTransaction();
    $sql = "INSERT INTO todo (todo) VALUES (:todo)";
    $stmh = $pdo->prepare($sql);
    $stmh->bindValue(':todo', $_POST['todo_content'], PDO::PARAM_STR);
    $stmh->execute();
    $pdo->commit();
    $pdo->query("SET NAMES utf8");
} catch (PDOException $Exception) {
    $pdo->rollBack();
    print'error:' .$Exception->getMessage();
}
    while(1)
    {
        $row = $stmh->fetch(PDO::FETCH_ASSOC);// fetch one record
        if($row == false) // if no more data
        {
        break;// escape from the loop
    }
    ?>
    
      <p><?=htmlspecialchars($row['todo_content'], ENT_QUOTES)?></p><!-- Show database data -->
    
  <?php
    } // while closing tag
    $pdo = null;
?>
What I tried

Since the connection to the database is completed firmly and it has been confirmed that the data entered in the html form is inserted in the database, I wonder if there is a problem with the data display method,


changed to
→ nothing is displayed


that's all.
If i have any questions, please answer.