当我在公式器中键入信息并单击“提交”按钮时,用户将被添加到数据库中。 很好,但是当我刷新页面后,它再次添加了同一用户。我该如何停止该程序?
<div id="add" class="tabcontent" class="active">
<h3>Neuen User hinzufügen</h3>
<br>
<form class='formular' method="post" action="admin.php">
<p class="eigenschaften">User Name:</p>
<input type='text' name='u_name' placeholder='User Name'>
<br><br>
<p class="eigenschaften">Vorname:</p>
<input type='text' name='vorname' placeholder='Vorname'>
<br><br>
<p class="eigenschaften">Nachname:<p>
<input type='text' name='nachname' placeholder='Nachname'>
<br><br>
<p class="eigenschaften">Passwort:</p>
<input type='text' name='passwort' placeholder='Passwort'>
<br><br><br>
<button type='submit' name="btn" class="btn_speichern">Speichern</button>
</form>
<?php
$host = 'localhost';
$user = 'root';
$password = 'FIoLTAZo1pEar83N';
$dbname = 'studenten';
$dsn = 'mysql:host='. $host .';dbname='. $dbname;
$pdo = new PDO($dsn, $user, $password);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user_name = $_POST["u_name"];
$first_name = $_POST["vorname"];
$last_name = $_POST["nachname"];
$user_password = $_POST["passwort"];}
$sql = 'INSERT INTO studenten(user_name, first_name, last_name, user_password) VALUES(:user_name, :first_name, :last_name, :user_password)';
$stmt = $pdo->prepare($sql);
$stmt->execute(['user_name' => $user_name, 'first_name' => $first_name, 'last_name' => $last_name, 'user_password' => $user_password]);
$user_name = null;
$first_name = null;
$last_name = null;
$user_password = null;