2011-12-09 21 views
0

我在一個預先製作的項目中使用oop php在mysql數據庫中插入了一個表單數據。所有的工作都是正確的,但是在提交任何成功和失敗的信息後都沒有顯示。 我的表格示例代碼:在數據庫中插入數據時在oop上輸出的信息

performance.php->

<h1>Employee Review Form</h1> 
<form name="product" action="" method="post" id="customForm"> 
    <table> 
      <tr> 
     <td>Review Employee Id</td> 
     <td><input type="text" name="rcode" id="rcode" class="genInputBox" /></td> 
    </tr> 
     <tr> 
      <td>Domain Knowledge(Subject Matter)</td> 
      <td><select name="dk" id="dk"> 
        <option value="">Plz Select Ratting </option> 
        <option value="5">5</option> 
        <option value="4">4</option> 
        <option value="3">3</option> 
        <option value="2">2</option> 
        <option value="1">1</option> 
       </select></td> 
     </tr>and more............... 
      <input type="submit" value="register" id="submit" name="form_submit"/> 
        </td></tr> 
         </table> 
        </form> 

和表單提交過程

 <?php 

     if(isset($_POST) && isset ($_POST["form_submit"])){ 
    $valArr=array("review_emp_id"=>$_POST['rcode'],"subject_matter"=>$_POST['dk']); 
    $per_obj = new Performance(); 
    $per_obj->addPreformance($valArr, "employee_performance"); 


    } 
    ?> 

和我的課堂表現頁面是:

   <?php 
    require_once("admin/includes/class_common_lib.php"); 
    require_once("class.userinfo.inc.php"); 

    class Performance extends DataAccess{ 

var $db_obj = null; 
public function __construct() {  //for database connectivity 
    $this->db_obj = new DataAccess(); 
} 

public function addPreformance($key_values = array(), $table = null) { 
    $this->db_obj->table_name = $table; 
     $this->db_obj->addRecord($key_values); 


    } 
    } 

    ?> 

和類通用庫增加記錄功能代碼是:

    // Function for Add Record 
    function addRecord($key_values) 
    { 

     $cols=""; 
     $vals=""; 
     foreach($key_values as $key=>$value) 
     { 
      if ($key!="submit" and $key!="PHPSESSID" and $key!="image_name" and $key!="submit_button" and $key!="ext" and $key!="ext2" and $key!="img_name" and $key!="mode" and $value!="" and $key!="gpl" and $key!="ip1" and $key!="ip2" and $key!="ip3" and $key!="ip4"){ 
       $cols .= "`".$key."`,"; 
       is_string($value)? $vals .= "'".addslashes($value)."'," : $vals .= "'".$value."',"; 

      } 
     } 

     $cols = substr($cols, 0, -1); 
     $vals = substr($vals, 0, -1); 

     $insert_qry="insert into ". $this->table_name ."(". $cols .") values(". $vals .")"; 

     $r=mysql_query($insert_qry); 
     $this->msg = (!$r) ? f_add_msg : s_add_msg; 
     return $r; 
    } 

它是一個非常大的項目,我完成了其他人以前完成的所有過程。

現在我想顯示msz數據在提交表單後是否在數據庫中提交(成功或失敗)。

,我發現在配置文件中

 define ("s_add_msg", "Record successfully added."); 

    define ("f_add_msg", "Record not added. Please try again.&error=1"); 

我知道它的冗長的代碼,但我需要顯示會發生什麼,這些線。 所有功能工作正常,但 我怎麼能顯示performance.php頁成功或失敗的消息?請幫

+0

很難從您提供的代碼示例中發現錯誤。相關狀態消息正在db對象中設置,但在調用addPerformance之後沒有代碼來告訴如何檢索該消息。 – liquorvicar

+0

是的,先生,我告訴過,這是一個雙重和預先制定的項目,我只做了一些更正 – ravinath

回答

1

這是常見的編程使用Post/Redirect/Get模式在這樣的情況。沒有看到你的整個代碼庫快速修復,這可能是改變你的表單提交這樣的:

<?php 

    if(isset($_POST) && isset ($_POST["form_submit"])){ 
    $valArr=array("review_emp_id"=>$_POST['rcode'],"subject_matter"=>$_POST['dk']); 
    $per_obj = new Performance(); 
    $per_obj->addPreformance($valArr, "employee_performance"); 

    $redirectLink = "someOtherUrl.php?m=" . urlencode($per_obj->db_obj->msg); 
    header('Location: ' . $redirectLink); 
    die(); 
} 
?> 

這將重定向到您指定的新的URL,你應該能夠檢索使用$ _GET狀態消息[ 'M']。

最終你會希望在整個系統中以更簡潔的方式處理這個問題,但是如果你只是想修復遺留代碼,至少會讓你開始。