|
 |
|
ต้องการบันทึกข้อมูลทั้ง $_FILES และ $_POST ในเวลาเดียวกัน |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
include('../auth.php');
require_once('server.php');
$username = $_SESSION['username'];
$user_fullname = $_SESSION['user_fullname'];
$filename = $user_fullname . '_' . date("Y-m-d h:i:sa") .'.jpg';
$filepath = '../images/time_in/';
$reason = $_POST['cause_late'];
$th = date("H");
$tm = date("i");
if (isset($_POST['u_time_submit'])) {
global $late;
if ($th > 8) {
$late = "yes";
}
else if ($th == 8 && $tm > 30) {
$late = "yes";
}
else {
$late = NULL;
}
if(isset($_FILES['webcam'])) {
move_uploaded_file($_FILES['webcam']['tmp_name'], $filepath.$filename);
$sql="INSERT INTO tb_time_in(username,user_fullname,images,reason,late) values('$username', '$user_fullname', '$filename', '$reason', '$late')";
$result=mysqli_query($condb,$sql);
if($result) {
echo "<script>
alert('Add completed แจ้งเข้างานสำเร็จ!');
window.location.href='../index.php';
</script>";
} else {
echo "<script>
alert('Add completed แจ้งเข้างานสำเร็จ!');
window.history.back();
</script>";
exit();
}
}
mysqli_close($condb);
}
?>
หลังกด submit จอขาวไม่มีอะไรเกิดขึ้นครับ แต่ถ้าใช้ $_FILES อย่างเดียวมันแพทซ์ไฟล์กับบันทึกชื่อไฟล์ได้ปกติ แต่มันไม่บันทึก field ของ $_POST['cause_late'] ครับ
Tag : PHP, HTML, Windows

|
|
 |
 |
 |
 |
Date :
2021-06-28 14:21:57 |
By :
cannibidiol |
View :
502 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองย้ายการกำหนดตัวแปรไปไว้ใน if ทั้งหมด
|
 |
 |
 |
 |
Date :
2021-06-28 15:34:30 |
By :
TheGreatGod_of_Death |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ได้แล้วครับ
Code (PHP)
if (isset($_FILES['webcam'])) {
move_uploaded_file($_FILES['webcam']['tmp_name'], $filepath.$filename);
}
if (isset($_POST['u_time_submit'])) {
$reason = $_POST['cause_late'];
$th = date("H");
$tm = date("i");
if ($th > 8) {
$late = "lated";
}
else if ($th == 8 && $tm >= 30) {
$late = "lated";
}
else {
$late = NULL;
}
$sql="INSERT INTO tb_time_in(username,user_fullname,images,reason,late) values('$username', '$user_fullname', '$filename', '$reason', '$late')";
$result=mysqli_query($condb,$sql);
if($result) {
echo "<script>
alert('Add completed แจ้งเข้างานสำเร็จ!');
window.location.href='../index.php';
</script>";
} else {
echo "<script>
alert('ERROR เกิดข้อผิดพลาดในการบันทึกข้อมูล!');
window.history.back();
</script>";
exit();
}
mysqli_close($condb);
}
?>
|
 |
 |
 |
 |
Date :
2021-06-28 16:26:06 |
By :
cannibidiol |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|