[英]PDO inserting double data
我的代碼正在工作,除了它將雙重數據插入數據庫,例如,如果我輸入john作為用戶名,123輸入密碼,它會插入兩次! 我怎么能擺脫它?
<form method="POST">
<input type="text" name="username" placeholder="username"><br />
<input type="password" name="password" placeholder="password"><br />
<input type="submit">
</form>
<?php
if (isset($_POST['username'], $_POST['password'])) {
require 'core/connect.php';
$query = dbConnect()->prepare("INSERT INTO users (username, password) VALUES(?,?)");
$query->bindParam(1, $_POST['username']);
$query->bindParam(2, $_POST['password']);
$query->execute();
if ($query->execute()) {
echo 'Thank you! you may now log in <a href=\'index.php\'>here</a>';
} else {
echo 'Please go back, something was wrong.';
}
}
?>
你跑兩次
$query->execute();
if ($query->execute()) {
省略第一行
所以你留下來:
if (isset($_POST['username'], $_POST['password'])) {
require 'core/connect.php';
$query = dbConnect()->prepare("INSERT INTO users (username, password) VALUES(?,?)");
$query->bindParam(1, $_POST['username']);
$query->bindParam(2, $_POST['password']);
if ($query->execute()) {
echo 'Thank you! you may now log in <a href=\'index.php\'>here</a>';
} else {
echo 'Please go back, something was wrong.';
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.