我可以在Meta Http Equiv Refresh中传递变量吗?

时间:2012-06-26 22:59:48

标签: php

我刚刚完成了这个脚本它运行良好,但我很难将$ invite变量传递给register.php页面。有人可以告诉我如何实现这一目标吗?我把它定义为$ invite = $ _POST ['inviteinput'];

如何从index.php获取用户输入以转移到register.php?谢谢你的帮助!

HTML表格:

    <form action="index.php" method="post">
    What is your Invite Code?<BR />
    <input class="textbox" name="inviteinput" type="text" />
    <BR />
    <input type="hidden" name="formsubmitted" value="TRUE" />
    <input name="Submit" type="submit" value="Verify" />
    </form>

PHP:

<?PHP
include ('scripts/dbconnect.php');

if (isset($_POST['formsubmitted'])) {

if (empty($_POST['inviteinput'])) {
echo '<div class="errormsgempty"><u>ERROR</u>:<br>You must enter a valid invite code to proceed!</div>';
} else {


$invite = $_POST['inviteinput'];//else assign it a variable
$invite = stripslashes($invite);
$invite = mysql_real_escape_string($invite);

$sql = "SELECT yourMemberId FROM Register WHERE yourMemberId='$invite'";
$result = mysql_query($sql);

if(mysql_num_rows($result) > 0) {

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=register.php">';   
} else { 
echo '<div class="errormsgbox"><u>ERROR</u>:<br>The Invite Code you entered ' . $invite . ' is NOT a valid invite code!</div>';
//($notvalidcode = "The Invite Code you entered <strong>" . $invite . "</strong> is NOT a valid invite code!");
}
}
}
?>

2 个答案:

答案 0 :(得分:3)

绝对。只需将其添加到URL:

<meta http-equiv="Refresh" Content="0; url=register.php?var=value&othervar=hello" />

请注意,您最好使用:

header("Location: register.php?var=value&othervar=hello");
exit;

答案 1 :(得分:3)

有几种方法 将其保存在会话中

session_start();
$_SESSION['invite'] = $invite;

第二是你可以通过get

传递它
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=register.php?invite=' . $invite . '">'; 

我会建议选项2。 另外,你为什么要做$invite = $_POST['inviteinput'];两次?