Mini Shell
<?php
include '../db/database.php';
include 'function_date.php';
$teachercrID = $_POST['teachercrID'];
$crownID = $_POST['crownID'];
$year = $_POST['year'];
$date = $_POST['date'];
$date1 = mydate($date);
//เช็ค Username ซ้ำกันหรือไม่
$sql_year = "SELECT year FROM history_crown WHERE year='$year' AND teachercrID= '$teachercrID'";
$result_year = mysqli_query($link, $sql_year);
$is_year = mysqli_num_rows($result_year);
if ($is_year == 1) {
header('Content-Type: application/json');
$errors = "ปี พ.ศ ซ้ำกัน" . mysqli_error($link);
echo json_encode(array('status' => 'danger','message' => $errors));
exit;
}
$sql = "INSERT INTO `history_crown` (`teachercrID`, `crownID`, `year`, `date`) VALUES
('$teachercrID', '$crownID', '$year', '$date1')";
$result = mysqli_query($link, $sql);
if ($result) {
header('Content-Type: application/json');
echo json_encode(array('status' => 'success','message' => 'บันทึกข้อมูลเรียบร้อยแล้ว'));
} else {
header('Content-Type: application/json');
$errors = "ไม่สามารถบันทึกข้อมูลได้";
echo json_encode(array('status' => 'danger','message' => $errors));
}
Zerion Mini Shell 1.0