我有一个表单,一旦用户单击submit按钮,他就会被发送到save.php页面。在save.php页面上,表单的信息被发送到MySQL表。然而,在save.php页面上,我已经放置了一个rederict,将用户带到一个独特的页面,在那里他可以看到他刚刚输入的信息。
为此,我在表中添加了用户的信息,并将其放入唯一页面的URL中。下面是代码中涉及到我所讨论的部分。
$registerquery = mysql_query("INSERT INTO users_event (x, x, x, x, x, Confirm_code) VALUES('".$x."', '".$_SESSION['x']."', '".$x."', '".$x."', '".$x."', '".$confirm_code=md5(uniqid(rand())). "'); ");
if($registerquery)
{
echo "<h1>Congrats!</h1>";
echo "<p>All perfect!</p>";
echo "<meta http-equiv='refresh' content='0;URL=show2.php?confirm_code=<?php echo $registerquery[Confirm_code];?> />";
}我的问题是,confirm_code永远不会出现在URL中。所以,唯一的一页也没有。如何在URL中显示确认代码?
发布于 2013-08-04 03:30:34
您的确认代码永远不会显示,因为查询很可能失败。可以在查询结束时使用or die(mysql_error())验证- $registerquery = mysql_query(...) or die(mysql_error())。
在查询之外创建变量,然后将其添加到查询和元字符串中。
$confirm_code=md5(uniqid(rand()));
$registerquery = mysql_query("INSERT INTO users_event (x, x, x, x, x, Confirm_code) VALUES('".$x."', '".$_SESSION['x']."', '".$x."', '".$x."', '".$x."', '".$confirm_code. "'); ");
if($registerquery){
echo "<h1>Congrats!</h1>";
echo "<p>All perfect!</p>";
echo "<meta http-equiv='refresh' content='0;URL=show2.php?confirm_code=".$confirm_code."' />";
}发布于 2013-08-04 03:25:06
您正在插入MySQL,而不是选择。$registerquery变量不包含代码。因此,在该查询之前,请将确认代码保存在某个php变量中。
$temp_code = Confirm_code; //whatever the code is然后
$registerquery = mysql_query("INSERT INTO users_event (x, x, x, x, x, Confirm_code) VALUES('".$x."', '".$_SESSION['x']."', '".$x."', '".$x."', '".$x."', '".$confirm_code=md5(uniqid(rand())). "'); ");
if($registerquery)
{
echo "<h1>Congrats!</h1>";
echo "<p>All perfect!</p>";
echo "<meta http-equiv='refresh' content='0;URL=show2.php?confirm_code=<?php echo $temp_code;?> />"; }使用这个临时变量而不是$registerqueryConfirm_code
另一种方法是先插入,然后选择我认为你真的不想做的。
发布于 2013-08-04 03:27:11
我想你是说使用你的$confirm_code变量吧?因为您要插入数据库,而不是选择。
echo '<meta http-equiv="refresh" content="0;URL=show2.php?confirm_code=' . $confirm_code . '" />';https://stackoverflow.com/questions/18039408
复制相似问题