Php 在oop中打印有关在数据库中插入数据的消息
我在一个预先制作的项目中使用oop php在mysql数据库中插入表单数据。所有工作都是正确的,但在提交任何成功和失败的消息后都不会显示。 我的表单示例代码是: performance.php->Php 在oop中打印有关在数据库中插入数据的消息,php,mysql,oop,Php,Mysql,Oop,我在一个预先制作的项目中使用oop php在mysql数据库中插入表单数据。所有工作都是正确的,但在提交任何成功和失败的消息后都不会显示。 我的表单示例代码是: performance.php-> <h1>Employee Review Form</h1> <form name="product" action="" method="post" id="customForm"> <table> <tr&
<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>
这是一个非常大的项目,我做了所有其他人之前做的过程
现在我想显示msz的数据是否提交在数据库中(成功或失败)后提交的形式
我在配置文件中找到了这些行
define ("s_add_msg", "Record successfully added.");
define ("f_add_msg", "Record not added. Please try again.&error=1");
我知道它的代码很长,但我需要说明会发生什么。
所有功能都正常工作,但
如何在performance.php页面中显示成功或失败消息?请帮助在编程中,在这种情况下使用该模式是很常见的。在看不到整个代码库的情况下,快速修复此问题的方法可能是更改表单提交,如下所示:
<?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,在那里您应该能够使用$\u GET['m']检索状态消息
最终,您可能希望在整个系统中以更干净的方式处理此问题,但如果您只是尝试修复旧代码,那么至少可以让您开始使用。从您提供的代码示例中很难看出哪里出了问题。db对象中正在设置相关的状态消息,但调用addPerformance后没有代码来说明如何检索该消息。是的,先生,我告诉过这是一个bis和预先制作的项目,我只是在做一些更正
// 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;
}
define ("s_add_msg", "Record successfully added.");
define ("f_add_msg", "Record not added. Please try again.&error=1");
<?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();
}
?>