通过“window.location.href”传递参数 [英] Passing parameter through "window.location.href"
本文介绍了通过“window.location.href”传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<!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>
在question.php文件中,我想将$ q_id作为$ _ GET ['q_id'];
At "question.php" file, I want to receive "$q_id" as "$_GET['q_id'];"
我可以将第17行的$ q_id传递给question.php第26行?
Can I pass "$q_id" of line 17 to "question.php" page of line 26?
推荐答案
只需将它作为查询字符串添加到javascript中, b $ b
Just add it in as a query string in the javascript
echo ("<script language='JavaScript'>
window.location.href='question.php?q_id=$q_id';
window.alert('Thank You! Your answer is online now.')
</script>");
这篇关于通过“window.location.href”传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文