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.
 
 
 
 
 
 

85 lines
3.9 KiB

<?php
include "header.php";
if(isset($_POST['update'])) {
function user_input( $data ) {
$data1 = trim($data);
$data2 = stripslashes($data1);
$data3 = htmlspecialchars($data2);
return $data3;
}
$id = $_POST['id'];
$expert_id = user_input($_POST["expert_id"]);
$personal_id = user_input($_POST["personal_id"]);
$name = user_input($_POST["name"]);
$title = user_input($_POST["title"]);
$major = user_input($_POST["major"]);
$tel = user_input($_POST["tel"]);
$tel_count = user_input($_POST["tel_count"]);
$chat_id = user_input($_POST["chat_id"]);
$chat_count = user_input($_POST["chat_count"]);
$video_call = user_input($_POST["video_call"]);
$video_count = user_input($_POST["video_count"]);
$onsite_call = user_input($_POST["onsite_call"]);
$onsite_count = user_input($_POST["onsite_count"]);
$creater = user_input($_POST["creater"]);
$create_at = date('Y/m/d H:i:s');
$file_name = $_FILES["fileToUpload"]["name"];
$temp_file_name = $_FILES["fileToUpload"]["tmp_name"];
$file_size = $_FILES["fileToUpload"]["size"];
$target_dir = "expert-uploads/";
$target_file = strtolower($target_dir . basename($file_name));
$upload_ok = 1;
$img_file_type = pathinfo($target_file, PATHINFO_EXTENSION);
if(strlen($target_file) <= strlen("expert-uploads/")){
$db_query = "UPDATE expert set expert_id = '$expert_id', personal_id = '$personal_id', name = '$name', title = '$title', major = '$major', tel = '$tel', tel_count = '$tel_count', chat_id = '$chat_id', chat_count = '$chat_count', video_call = '$video_call', video_count = '$video_count', onsite_call = '$onsite_call', onsite_count = '$onsite_count', create_at = '$create_at' WHERE id='$id'";
mysqli_query($link, $db_query);
}else {
if($file_size > 500000) {
echo "<font color='#FF0000'>Please enter a file size between 5mb</font>";
$upload_ok = 0;
} else { //
//Allow certain file formats
if($img_file_type != "jpg" && $img_file_type != "png" && $img_file_type != "jpeg" && $img_file_type != "gif") {
//echo "JPG, PNG, JPEG and GIF files are allowed";
$upload_ok = 0;
} else {
//Check if $upload_ok is set to 0 by an error
if($upload_ok === 0) {
echo "<font color='#FF0000'>File has not been uploaded</font>";
} else {
if(move_uploaded_file($temp_file_name, $target_file)){
$db_query = "UPDATE expert set expert_id = '$expert_id', personal_id = '$personal_id', name = '$name', title = '$title', picture = '$target_file', major = '$major', tel = '$tel', tel_count = '$tel_count', chat_id = '$chat_id', chat_count = '$chat_count', video_call = '$video_call', video_count = '$video_count', onsite_call = '$onsite_call', onsite_count = '$onsite_count', create_at = '$create_at' WHERE id='$id'";
mysqli_query($link, $db_query);
}
}
}
}
}
$affected = mysqli_affected_rows($link);
mysqli_close($link);
if ($affected > 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('update成功');";
echo "location.href='expert-index.php?function_name=expert&".$token_link."';";
echo "</script>";
} elseif ($affected == 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('無新增資料')";
echo "location.href='expert-index.php?function_name=expert&".$token_link."';";
echo "</script>";
} else {
echo "{$db_query} 語法執行失敗,錯誤訊息SSS: " . mysqli_error($link);
}
}
?>