2012-04-11 66 views
2

如何向URL whit PHP添加參數。在JavaScript中我使用類似使用PHP修改網址

document.URL = "?param1=sth". 

我有一個有值等於文章編號(從數據庫)的文章絲毫複選框的列表,並在用戶檢1複選框,我想他重定向到http://blablabla.com/edit?article_name=1(article id);

$checkbox = "<input type=\"checkbox\" name=\"article[]\" value=\"{$article["id"]}\"/>"; 

$checkbox是根據數據庫中的文章數自動生成的。

if(isset($_POST['edit']) AND isset($_POST['article'])){ 
    $articol = $_POST['article']; 
    if (is_array($articol)) { 
      $contor = 0; 
       foreach ($articol as $item) { 
        if(isset($item)) 
         $contor ++; 
       } 
       if($contor == 1){ 
       **redirect user to edit.php?article_name=1;** 
       }else { 
       echo "<script type='text/javascript'>"; 
       echo "alert(\"You can't edit more than 1 article!\")"; 
       echo "</script>"; 
       } 

      } 
     } 
+0

複選框暗示選擇* zero或more *選項,而不是* one *。這就是單選按鈕的用途。 – DCoder 2012-04-11 19:28:32

回答

2

您可以使用header,但你必須確保前不要發送任何輸出,或以其他方式使用輸出緩衝。此外,撥打header並不會實際結束腳本,因此如果您想要在此停止,使用exit是件好事。

header('Location: edit.php?article_name=1'); 
exit; 
+0

謝謝你們!問題解決了! – TGeorge 2012-04-11 19:37:02