2014-02-18 75 views
0

我的標題不起作用。標題不起作用

<?php 
$name = mysql_prep($_POST['name']); 
$pastor = mysql_prep($_POST['pastor']); 
$head = mysql_prep($_POST['head']); 
$schedule = mysql_prep($_POST['schedule']); 
$venue = mysql_prep($_POST['venue']); 
$id = mysql_prep($_GET['ministryid']); 
$errors = array(); 

    $required_field = array('name', 'pastor', 'address', 'schedule', 'venue'); 
    foreach ($required_field as $fieldname) { 
    if(!isset($_POST[$fieldname]) || empty($_POST[$fieldname])) { 
     $errors[] = $fieldname; 
     echo "Sorry, you missed to complete {$fieldname} <br />"; 
     } 
    else { 
     $query = "UPDATE ministry SET 
     name = '{$name}', 
     pastor = '{$pastor}', 
     head = '{$head}', 
     schedule = '{$schedule}', 
     venue = '{$venue}' 
     WHERE id = {$id}"; 

     mysql_query($query); 
     if(mysql_affected_rows() == 1) {     
      header('location: editministry.php?'); 
      exit; 
     } else { 
      echo "Updating Failed on {$s_ministry['name']} <b />".mysql_error(); 
      exit; 
     } 
    } 
    } 

require_once("include/footer.php"); 

每次成功更新時,鏈接都會更改其地址。

例如,當我更新id = 3時,地址將更改爲editministry.php?ministryid = 3。

+0

嘗試刪除從標題位置,標題(「Location:editministry.php」); – PravinS

+0

仍然不能正常工作:( – user3278904

+0

if if(mysql_affected_rows()== 1)condition is satisfied ?,嘗試echo mysql_affected_rows();並檢查你得到的值或者你可以檢查是否(mysql_affected_rows()> 0)條件 – PravinS

回答

0

你不會發送任何東西沿你的網址,這就是爲什麼你的頭不起作用。檢查你自己。

if(mysql_affected_rows() == 1) {     
      header('location: editministry.php?'); 
      exit; 

您的鏈接將成爲用途不同的baseUrl/editministry.php?。它的搜索比一個變量,它沒有定義。我不確定你實際上可以傳遞一個你沒有在鏈接中定義的變量,但它會將它發送到那裏。不知道。但是,如果你只是將它告訴沒有問號的硬鏈接,它應該進入該頁面。對我來說,至少在我的代碼中起作用。對你來說會是:

if(mysql_affected_rows() == 1) {     
      header('location: editministry.php'); 
      exit; 

在我的代碼,它看起來是這樣的: 「?」

header("Location: http://" . strip_tags($_SERVER ['HTTP_HOST']) . "/newHolo/index.php");