我有一个表单,当我按下提交按钮时,我会根据需要处理数据。我想要的是转到另一页或上一页。我的页面是什么,起初是一个链接列表,当我点击一个链接时,另一个页面会打开,里面有问题要回答,我回答完之后,我需要回到选择页面。我试过header()
了,因为这是大多数人说要使用的,但我停留在同一页面上,我尝试了使用,<meta http-equiv="refresh" content="0" url="the page to go to">
但这似乎一遍又一遍地刷新同一页面。当我按下提交并处理问题时,我怎样才能使它返回到选择页面。
谢谢
注意:如果需要代码,请告诉我,以便我发布它们。
编辑:
这是我尝试使用header()
and的代码http_redirect()
<?php
// topic 1
try {
$db = new PDO("mysql:dbname=mawarid;host=localhost", "khaled", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$q_qry = "select * from question where question_topic='1';";
$questions = $db->query($q_qry)->fetchAll();
} catch (PDOException $ex) {
// code here for handling error
print "error";
print "\n".$ex->getMessage()."\n";
}
?>
<!doctype html>
<html>
<html>
<meta charset="UTF-8">
<title>topic 1</title>
</html>
<body>
<h1>topic 1:</h1>
<form method="post" action="">
<ol>
<?php
foreach ($questions as $question) {
$qa_qry = "select * from answer where question='$question[0]';";
$ans = $db->query($qa_qry)->fetchAll();
?>
<li><?= $question[1] ?></li>
<?php
foreach ($ans as $a) {
$radio_name = "q".$question[0];
?>
<label><input type="radio" name="<?= $radio_name ?>" value="<?= $a[0] ?>"><?= $a[1] ?></label><br/>
<?php
}
}
?>
</ol>
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>
<?php
session_start();
if(isset($_POST["submit"])) {
$user_ans = array();
for($i = 1; $i <= 10; $i++) {
$ans_access = "q".$i;
$user_ans[$i] = $_POST[$ans_access];
}
// $correct = $_SESSION["contestant_name"]["correct"];
// $wrong = $_SESSION["contestant_name"]["wrong"];
$correct = 0;
$wrong = 0;
foreach ($questions as $question) {
if ($question[2] == $user_ans[$question[0]])
$correct++;
else
$wrong++;
}
$_SESSION["contestant_name"]["topics_score_correct"][0] = $correct;
$_SESSION["contestant_name"]["topics_score_wrong"][0] = $wrong;
$_SESSION["contestant_name"]["topics_done"][0] = TRUE;
$_SESSION["contestant_name"]["correct"] += $correct;
$_SESSION["contestant_name"]["wrong"] += $wrong;
$_SESSION["contestant_name"]["last_topic_id"] = 1;
// header("Location:choosetopic.php");
http_redirect("choosetopic.php");
}
?>