这是我进行更新查询的方式,该查询正在运行,但没有成功,也没有错误结果。虽然我已经在MySql工作台中使用参数手动测试了查询,但是一切正常。我所缺少的。我也不知道为什么不成功,为什么不抛出任何异常或错误。
function UpdateLeaveDetailRequestStatus(){
global $connPDO;
date_default_timezone_set("Asia/Karachi");
//$connPDO->beginTransaction();
$currentDate = date('Y-m-d H:i:s');
$binds = array(
":leave_start_date" => $_POST["leaveStartDate"],
":leave_end_date" => $_POST["leaveEndDate"],
":leave_total_days" => $_POST["leaveTotalDays"],
":leave_type" => $_POST["leaveType"],
":leave_in_out_time" => $_POST["leaveInOutTime"],
":leave_duration" => $_POST["leaveDuration"],
":leave_reason" => $_POST["leaveReason"],
":leave_current_status_id" => $_POST["leaveCurrentStatusId"],
":leave_current_status_set_by" => $_COOKIE["userID"],
":leave_current_status_set_dateTime" => $currentDate,
":leave_detail_id" => $_POST["leaveDetailId"]
);
echo $_POST["empId"] ."\n";
echo $_POST["leaveStartDate"]. "\n";
echo $_POST["leaveEndDate"]. "\n";
echo $_POST["leaveTotalDays"]. "\n";
echo $_POST["leaveType"]. "\n";
echo $_POST["leaveInOutTime"]. "\n";
echo $_POST["leaveDuration"]. "\n";
echo $_POST["leaveReason"]. "\n";
echo $_POST["leaveCurrentStatusId"]. "\n";
echo $_COOKIE["userID"]. "\n";
echo $currentDate. "\n";
echo $_POST["leaveDetailId"]. "\n";
$sqlProjectQueueUpdate =
"Update `ttl_employee_switch`.`tbl_emp_leave_details`
SET
`leave_start_date` = `:leave_start_date`,
`leave_end_date` = `:leave_end_date`,
`leave_total_days` = `:leave_total_days`,
`leave_type` = `:leave_type`,
`leave_in_out_time` = `:leave_in_out_time`,
`leave_duration` = `:leave_duration`,
`leave_reason` = `:leave_reason`,
`leave_current_status_id` = `:leave_current_status_id`,
`leave_current_status_set_by` = `:leave_current_status_set_by`,
`leave_current_status_set_dateTime` = `:leave_current_status_set_dateTime`
WHERE `leave_detail_id` = `:leave_detail_id`";
echo $sqlProjectQueueUpdate;
$statement = $connPDO->prepare($sqlProjectQueueUpdate);
$output = $statement->execute($binds);
//$output = CustomPDO($connPDO, $sqlProjectQueueUpdate, $binds);
echo $output;
}
这是调用上述函数的javascript:
if(leaveInOutTime == null || leaveInOutTime == undefined ||leaveInOutTime=="")
{
leaveInOutTime = "00:00:00";
}
var data = {};
var actionName= "";
data = {
//"action" : actionName,
"empId" : empID,
"leaveStartDate" : leaveStartDate,
"leaveEndDate" : leaveEndDate,
"leaveTotalDays" : leaveTotalDays,
"leaveDuration" : leaveDuration,
"leaveType" : leaveType,
"leaveInOutTime" : leaveInOutTime,
"leaveReason" : leaveReason
};
//alert($("#selectedLeaveFormId").attr("leave-id"));
if(isInsert ==false){
data["leaveCurrentStatusId"] = 1;
data["leaveDetailId"] = $("#selectedLeaveFormId").attr("leave-id");
data["action"] = "UpdateLeaveDetailRequestStatus";
}
else
{
data["action"] = "GenerateLeaveDetailRequest";
}
console.log(data);
console.log(empID);
console.log(leaveStartDate);
console.log(leaveEndDate);
console.log(leaveTotalDays);
console.log(leaveDuration);
console.log(leaveType);
console.log(leaveInOutTime);
console.log(leaveReason);
$.ajax({
url : baseURL + "EmpLeave.php",
type : "POST",
data : data,
success : function(data, textStatus, XMLHttpRequest) {
console.log(data);
if(data == 1)
{
ClearForm();
if(isInsert){
console.log("Successful entry" + data);
}else{
alert("Leave Reocrd Updated.")
}
}
else if(data == 2)
{
alert("Failed to generate leave request.");
}
else
{
console.log(data);
alert("An error occurred, please Contact Administrator. " + data);
}
},
error: function(jqXHR, textStatus, errorThrown) {
alert("An error occured when adding Project Question. Please Contact Administrator."+ errorThrown);
}
});
答案 0 :(得分:1)
请摆脱所有这些反引号:
$sqlProjectQueueUpdate =
"UPDATE ttl_employee_switch.tbl_emp_leave_details
SET
leave_start_date = :leave_start_date,
leave_end_date = :leave_end_date,
leave_total_days = :leave_total_days,
leave_type = :leave_type,
leave_in_out_time = :leave_in_out_time,
leave_duration = :leave_duration,
leave_reason = :leave_reason,
leave_current_status_id = :leave_current_status_id,
leave_current_status_set_by = :leave_current_status_set_by,
leave_current_status_set_dateTime = :leave_current_status_set_dateTime
WHERE leave_detail_id = :leave_detail_id";
反引号不属于列分配的RHS,它应该只是字符串(或其他类型)文字。无论如何,由于您的列名和表名不是保留的MySQL关键字,因此这里不需要反引号。