Php 每次我刷新页面时,程序都会添加一个用户
当我在公式中输入信息并点击提交按钮时,用户将被添加到数据库中。 这很好,但当我刷新页面之后,它会再次添加相同的用户。我怎样才能停止程序来做这件事Php 每次我刷新页面时,程序都会添加一个用户,php,database,user-interface,refresh,Php,Database,User Interface,Refresh,当我在公式中输入信息并点击提交按钮时,用户将被添加到数据库中。 这很好,但当我刷新页面之后,它会再次添加相同的用户。我怎样才能停止程序来做这件事 <div id="add" class="tabcontent" class="active"> <h3>Neuen User hinzufügen</h3> <br> <form class='formular' method="post" action="admin.php">
<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;
新用户欣祖富根
用户名:
Vorname:
Nachname:
通行证:
斯皮切恩
我想你应该在提交表单后阅读POST/Redirect/GET。你应该重置表单字段。好的,谢谢,我会试试的