在我的网站上,我有一个提交表格:
当我按下此提交按钮时,名称已保存到我的数据库中,这很好,但我也希望该按钮将我带到主页。现在,它带我到一个页面,上面说致命错误
但是,当我按URL链接并按Enter时,它将带我到主页。如何在不选择/按URL链接并按Enter的情况下将页面重定向到首页?这是我的代码:
代码:
<?php
require_once "library/connection.php";
$stmt = $conn->prepare("SELECT * FROM usernames ORDER BY scores DESC LIMIT 10");
function createLeaderBoard($stmt)
{
$stmt->execute();
$stmt->rowCount();
$data = $stmt->fetchAll();
foreach ($data as $row)
{
?>
<tr>
<td><?php echo $row['users']; ?></td>
<td><?php echo $row['Scores']; ?></td>
</tr>
<?php
}
}
if (isset($_POST["firstname"]))
{
$firstname = $_POST["firstname"];
$score = $_POST["score"];
$stmt = $conn->prepare("INSERT INTO `usernames` (`users`, `Scores`) VALUES ('" . $firstname . "','" . $score . "');");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}
?>
希望我的英语很好,我也希望你能理解我。所有的帮助将不胜感激:)
改变这个
if (isset($_POST["firstname"])) {
$firstname = $_POST["firstname"];
$score = $_POST["score"];
$stmt = $conn->prepare("INSERT INTO `usernames` (`users`, `Scores`) VALUES ('" . $firstname . "','" . $score . "');");
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
}
到
if (isset($_POST["firstname"])) {
$firstname = $_POST["firstname"];
$score = $_POST["score"];
$stmt = $conn->prepare("INSERT INTO `usernames` (`users`, `Scores`) VALUES ('" . $firstname . "','" . $score . "')");
if($stmt->execute()){
// redirect the user to homepage.php
header("Location: homepage.php");
exit();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句