2013-08-04 21 views
0

我有一個表單,一旦用戶點擊提交按鈕,他就會發送到save.php頁面。在save.php頁面上,表單的信息被髮送到MySQL表格。但是,在save.php頁面上,我放置了一個rederict,將用戶帶到一個獨特的頁面,在那裏他可以看到他剛輸入的信息。獲取MySQL值在URL中放置

要做到這一點,我把與用戶的信息的唯一代碼放在表中,以放置在「獨特的頁面」的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中?

+0

使用'show2.php?confirm_code = <?php echo $ confirm_code; ?> –

+0

它不工作... – freddy

+0

你不能在'mysql_query()'函數內創建一個php變量。 – Sean

回答

1

您的確認代碼永遠不會顯示,因爲您的查詢是最有可能失敗。您可以在查詢結束時使用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."' />"; 
} 
1

您正在插入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;?> />"; } 

使用的是臨時變量,而不是$ registerquery [CONFIRM_CODE]

另一種方式將是先插入,然後選擇,我覺得你真的不想做。

0

我假設你的意思是使用你的$confirm_code變量?因爲你插入到數據庫中,而不是選擇

echo '<meta http-equiv="refresh" content="0;URL=show2.php?confirm_code=' . $confirm_code . '" />'; 
0

您在將值插入到數據庫的同時將值分配給$ confirm_code。只要改變:

$registerquery[Confirm_code] 

$confirm_code