<!doctype html>
<html>
<head>
<title>Post Answer</title>
</head>
<body>
<?php
include ("connection.php");
$result = mysqli_query($con, "SELECT * FROM student_table WHERE SID='$_POST[sid]'") or die('Query failed');
$tmp = mysqli_fetch_array($result);
$nn = $tmp['nickname'];
$a = $_POST['answer'];
$sid = $tmp['SID'];
$c = $tmp['course'];
$q_id = $_POST['q_id'];
$sql = mysqli_connect("127.0.0.1", "root", "", "project");
$sql = "INSERT INTO answer_table (nickname, answer, SID, vote, course) VALUES ('$nn', '$a', '$sid', '', '$c')";
if (!mysqli_query($con, $sql)) {
die('Error: ' . mysqli_error($con));
}
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.location.href='question.php';
window.alert('Thank You! Your answer is online now.')
</SCRIPT>");
?>
</body>
</html>
at&#34; question.php&#34;文件,我想收到&#34; $ q_id&#34;作为"$_GET['q_id'];"
我可以通过&#34; $ q_id&#34;第17行到#34; question.php&#34;第26行的页面?
答案 0 :(得分:1)
只需将其添加为javascript中的查询字符串
即可echo ("<script language='JavaScript'>
window.location.href='question.php?q_id=$q_id';
window.alert('Thank You! Your answer is online now.')
</script>");
答案 1 :(得分:-1)
虽然已经晚了4年,但是@Seth的答案可能不正确。将PHP变量放在Javascript中无效,必须将其回显。
echo ("<script language='JavaScript'>
window.location.href='question.php?q_id=<?php echo $q_id ?>';
window.alert('Thank You! Your answer is online now.')
</script>");
“ <?php echo $ q_id?>”会将$ q_id中包含的值传递给JS函数。