You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

66 lines
2.2 KiB

<?php
include "header.php";
include_once "./contract/conn.php";
if (isset($_POST['update'])) {
function user_input($data)
{
$data1 = trim($data);
$data2 = stripslashes($data1);
$data3 = htmlspecialchars($data2);
return $data3;
}
$id = $_POST['id'];
$sql = "SELECT * FROM schedule WHERE id = '$id'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$checkRepaireIsit = $stmt->fetch(PDO::FETCH_ASSOC);
if (!empty($checkRepaireIsit)) {
echo "<script type ='text/JavaScript'>";
echo "alert('此單號已經有保養人員');";
echo "location.href='schedule-index.php?function_name=schedule&" . $token_link . "';";
echo "</script>";
}
$contractno = user_input($_POST["contractno"]);
$facilityno = user_input($_POST["facilityno"]);
$repairerid = user_input($_POST["repairerid"]);
$creater = user_input($_POST["creater"]);
$create_at = date('Y/m/d H:i:s');
$sql = "SELECT name FROM account WHERE accountid = '$repairerid'";
$stmt = $conn->prepare($sql);
$stmt->execute();
$account = $stmt->fetch(PDO::FETCH_ASSOC);
$repairername = $account['name'];
$db_query = "UPDATE schedule set
repairerid = '$repairerid',
repairername = '$repairername',
updater = '$creater',
update_at = '$create_at' WHERE contractno='$contractno' AND facilityno='$facilityno'";
$stmt = $conn->prepare($db_query);
$stmt->execute();
$affected = $stmt->rowCount();
if ($affected > 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('update成功');";
echo "location.href='schedule-index.php?function_name=schedule&" . $token_link . "';";
echo "</script>";
} elseif ($affected == 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('無新增資料');";
echo "location.href='schedule-index.php?function_name=schedule&" . $token_link . "';";
echo "</script>";
} else {
echo "{$db_query} 語法執行失敗,錯誤訊息SSS: ";
}
}