我有一个非常有趣的问题。只有部分值被输入到我的数据库中。
我有一个包含表单的页面。用户将填写表格并提交。所有 POST 值都是正确的,并且正在提交到数据库。一个特定的值 ($criteria) 仅提交字符串的最后一部分。如果我回显 $criteria 的值,它就在那里,但是当我在 mysqlAdmin 中查看它时,它只有一部分在那里。
它应该提交:
Communication | 1 | dsafadf | Customer Service | 2 | asdfadf | Dependability | 3 | asdfadsf | Initiative | 4 | dsafadsfa | Job Knowledge | 5 | dsadafsadsf | Judy | 1 | asdfasdf | Punctuality | 2 | asdfdasdfadsf |
但在数据库中我只得到 - | 准时 | 2 | asdfdasdfadsf |
我尝试使用 mysqlAdmin 手动添加值,它工作正常。
如果有其他信息需要帮助我会补充。
感谢大家!!
这是我的插入脚本:
public function insertReview() {
$fk_employee = $_POST['fk_employee'];
// Current Date returned from JQuery and formatted to add to DB.
$cdate = $_POST['current_date'];
$current_date = explode("/", $cdate);
$cmonth = $current_date[0];
$cday = $current_date[1];
$cyear = $current_date[2];
$current_dateA = array($cyear, $cmonth, $cday);
$review_date = implode("-", $current_dateA);
// Review Begin Date returned from JQuery Datepicker and formatted to add to DB.
$bdate = $_POST['r_period_begin'];
$begin_date = explode("/", $bdate);
$bmonth = $begin_date[0];
$bday = $begin_date[1];
$byear = $begin_date[2];
$begin_dateA = array($byear, $bmonth, $bday);
$r_period_begin = implode("-", $begin_dateA);
// Review End Date returned from JQuery Datepicker and formatted to add to DB.
$edate = $_POST['r_period_end'];
$end_date = explode("/", $edate);
$emonth = $end_date[0];
$eday = $end_date[1];
$eyear = $end_date[2];
$end_dateA = array($eyear, $emonth, $eday);
$r_period_end = implode("-", $end_dateA);
// Criteria
$criterias = $_POST['criteria'];
//var_dump($criterias);
$criteriaValue = $_POST['criteriaValue'];
//var_dump($criteriaValue);
$comments = $_POST['Comments'];
foreach ($criteriaValue as $key => $value ){
foreach( $criterias as $criteria ){
if( $criteria == $key ){
$string1 = $key;
foreach( $comments as $comment => $comm ){
if( $string1 == $comment ){
$string3 = $comm;
}
}
}
}
//echo $key . '<br>';
foreach ( $value as $result ){
$string2 = $result;
}
$criteria = mysql_real_escape_string( $string1 . ' | ' . $string2 . ' | ' . $string3 . ' | ' );
echo $criteria;
}
// End of Criteria
$job_knowledge = $_POST['job_knowledge'];
$jk_comments = $_POST['jk_comments'];
$work_quality = $_POST['work_quality'];
$wq_comments = $_POST['wq_comments'];
$attendance = $_POST['attendance'];
$attend_comments = $_POST['attend_comments'];
$initiative = $_POST['initiative'];
$init_comments = $_POST['init_comments'];
$communication = $_POST['communication'];
$comm_comments = $_POST['comm_comments'];
$dependability = $_POST['dependability'];
$depend_comments = $_POST['depend_comments'];
$customer_service = $_POST['customer_service'];
$cs_comments = $_POST['cs_comments'];
$overall_rating = $_POST['overall_rating'];
$additional_comments = $_POST['additional_comments'];
$goals = $_POST['goals'];
$conn = parent::connect();
$sql = "INSERT INTO " . TBL_EMPLOYEE_REVIEW . " (
fk_employee,
review_date,
r_period_begin,
r_period_end,
job_knowledge,
jk_comments,
work_quality,
wq_comments,
attendance,
attend_comments,
initiative,
init_comments,
communication,
comm_comments,
dependability,
depend_comments,
customer_service,
cs_comments,
overall_rating,
additional_comments,
goals,
criteria
) VALUES (
:fk_employee,
:review_date,
:r_period_begin,
:r_period_end,
:job_knowledge,
:jk_comments,
:work_quality,
:wq_comments,
:attendance,
:attend_comments,
:initiative,
:init_comments,
:communication,
:comm_comments,
:dependability,
:depend_comments,
:customer_service,
:cs_comments,
:overall_rating,
:additional_comments,
:goals,
:criteria
)";
try {
$st = $conn->prepare( $sql );
$st->bindValue( ":fk_employee", $fk_employee, PDO::PARAM_STR );
$st->bindValue( ":review_date", $review_date, PDO::PARAM_STR );
$st->bindValue( ":r_period_begin", $r_period_begin, PDO::PARAM_STR );
$st->bindValue( ":r_period_end", $r_period_end, PDO::PARAM_STR );
$st->bindValue( ":job_knowledge", $job_knowledge, PDO::PARAM_STR );
$st->bindValue( ":jk_comments", $jk_comments, PDO::PARAM_STR );
$st->bindValue( ":work_quality", $work_quality, PDO::PARAM_STR );
$st->bindValue( ":wq_comments", $wq_comments, PDO::PARAM_STR );
$st->bindValue( ":attendance", $attendance, PDO::PARAM_STR );
$st->bindValue( ":attend_comments", $attend_comments, PDO::PARAM_STR );
$st->bindValue( ":initiative", $initiative, PDO::PARAM_STR );
$st->bindValue( ":init_comments", $init_comments, PDO::PARAM_STR );
$st->bindValue( ":communication", $communication, PDO::PARAM_STR );
$st->bindValue( ":comm_comments", $comm_comments, PDO::PARAM_STR );
$st->bindValue( ":dependability", $dependability, PDO::PARAM_STR );
$st->bindValue( ":depend_comments", $depend_comments, PDO::PARAM_STR );
$st->bindValue( ":customer_service", $customer_service, PDO::PARAM_STR );
$st->bindValue( ":cs_comments", $cs_comments, PDO::PARAM_STR );
$st->bindValue( ":overall_rating", $overall_rating, PDO::PARAM_STR );
$st->bindValue( ":additional_comments", $additional_comments, PDO::PARAM_STR );
$st->bindValue( ":goals", $goals, PDO::PARAM_STR );
$st->bindValue( ":criteria", $criteria, PDO::PARAM_STR );
$st->execute();
parent::disconnect( $conn );
} catch ( PDOException $e ) {
parent::disconnect( $conn );
die( "Query failed: " . $e->getMessage() );
}
}