我想讓用戶通過提交按鈕接受/拒絕事件的請求。信息被循環顯示(用戶名,位置,接受,拒絕)。接受/拒絕提交按鈕循環與PHP
現在2個用戶正在顯示;用戶1和用戶2(當前用於測試)。無論如何,我試圖讓正確的用戶名使用正確的用戶名。目前,無論我接受或拒絕哪個用戶,都會顯示用戶2。我試圖根據隱藏的輸入設置用戶標識的值,但它不能正常工作。
這是我的代碼。
for($i=0;$i<count($userExplode)-1;$i++){
$user = mysql_query("select userid,username from users where userid = ".$userExplode[$i]." ");
$user = mysql_fetch_array($user);
$userLoc = mysql_query("select userLocation from userinfo where userid = ".$userExplode[$i]." ");
$location = mysql_fetch_array($userLoc);
$locationExplode = explode("~",$location['userLocation']);
//the displayed output is working correctly so I know it's setting $user['userid'] properly
echo '<form method="post"><table><tr><td><a href="profile.php?userid=' . $user['userid'] . '">' . $user['username'] . '</a></td>
<td>' . $locationExplode[0] . ', ' . $locationExplode[1] . '</td>
<td><input type="hidden" name="userReq" value='.$user['userid'].'></td>
<td><input type="submit" name="accept" value="Accept Request" ></td>
<td><input type="submit" name="decline" value="Decline Request" ></td></tr>';
}
echo '</table></form>';
}
if(isset($_POST['accept'])){
echo $_POST['userReq']; //displays user 2 even if I click user 1
}
if(isset($_POST['decline'])){
echo $_POST['userReq']; //also displays user 2 even if i click user 1
}
}
你應該使用'$ _GET'而不是'$ _POST' – Gaurav 2012-02-11 19:59:03
感謝您的提示!使用$ _GET來安全嗎?我想我只需再次檢查其他頁面,只有在事件的創建者是訪問該頁面的頁面時才允許。 – user1104854 2012-02-11 20:02:42
如果您安全使用它是安全的。只有管理員纔可以提出這些要求。 – Richard 2012-02-11 20:04:21