2017-06-22 91 views
1

我試過使用ob_start();和exit(); ,兩者都不能正常工作,請指教,非常感謝你php頭功能不起作用

<?php 
    ob_start(); 

    // connect to the database 
    include('connect-db.php'); 

    // check if the form has been submitted. 
    // If it has, start to process the form and save it to the database 
    // once saved, redirect back to the view page 
    if (isset($_POST["submit"])) 
    { 
     foreach ($_POST['patientid'] as $index => $patientid) 
     { 
      $id = mysql_real_escape_string($_POST['id'][$index]); 
      $data1 = mysql_real_escape_string($patientid); 
      $data2 = mysql_real_escape_string($_POST['vaccineid'][$index]); 
      $data3 = mysql_real_escape_string($_POST['vaccinename1'][$index]); 
      $data4 = mysql_real_escape_string($_POST['vaccinename2'][$index]); 
      $data5 = mysql_real_escape_string($_POST['vaccinename3'][$index]); 
      $data6 = mysql_real_escape_string($_POST['totalnoofinjection'][$index]); 
      $data7 = mysql_real_escape_string($_POST['nthinjection'][$index]); 
      $data8 = mysql_real_escape_string($_POST['date'][$index]); 
      $data9 = mysql_real_escape_string($_POST['nextdate'][$index]); 
      $data10 = mysql_real_escape_string($_POST['skip'][$index]); 
      $data11 = mysql_real_escape_string($_POST['language'][$index]);   

      mysql_query("UPDATE patientvaccinedetail SET patientid = '$data1', 
       vaccineid = '$data2', vaccinename1 = '$data3', 
       vaccinename2 = '$data4', vaccinename3 = '$data5', 
       totalnoofinjection = '$data6', nthinjection = '$data7', 
       date = '$data8', nextdate = '$data9', skip = '$data10', 
       language = '$data11' 
       WHERE id=$id") or die(mysql_error()); 

      header("Location: start.php"); 
      exit; 
     } 
    } 

剛剛更新,仍然之後exit

更正代碼cant't重定向到另一個頁面

+0

在本地主機上或生活運行? –

+0

請解釋「not working」的含義 – RamRaider

+1

**請**停止使用'mysql_ *'函數,因爲它們已被棄用並在PHP7中完全刪除! – Naruto

回答

3

你缺少分號:

exit;

+0

已添加它,但仍然無法正常工作,有什麼想法? – epiphany

1

使用ob_end_clean();頭調用之前並使用exit;代替exit

嘗試像下面

ob_end_clean(); 
header("Location: start.php"); 
exit; 
+0

會自動執行退出,因爲標題行會重定向到不同的頁面? – Ortund

+0

已添加它,但仍然不工作,有什麼想法? – epiphany

+0

@tam是否有錯誤? – Narayan