Mini Shell

Direktori : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/sp/admin_gard_new/
Upload File :
Current File : /var/www/vhosts/ccp.ac.th/smtp.ccp.ac.th/httpdocs/sp/admin_gard_new/insert_student.php

<?php
    include '../db/database.php'; 
    $year = $_POST['year'];
    $username = $_POST['username'];
    $sex = $_POST['sex'];
    $password = $_POST['username'];
    $name_peple = $_POST['name_peple'];
    $sname_peple = $_POST['sname_peple'];
    $user_class_id = $_POST['user_class_id'];
   
  //เช็ค Username ซ้ำกันหรือไม่
    $sql_student = "SELECT username FROM users_dg WHERE username='$username' AND year='$year'";
    $result_student = mysqli_query($link2, $sql_student);
    $is_student = mysqli_num_rows($result_student);
    if ($is_student == 1) {
        header('Content-Type: application/json');
        $errors = "รหัสนักเรียนนี้มีอยู่แล้วในระบบ" . mysqli_error($link);
        echo json_encode(array('status' => 'danger','message' => $errors));
        exit;
    }
    
    $sql = "INSERT INTO `users_dg` (`user_class_id`,`username`,`sex`,`password`,`name_peple`,`sname_peple`,`year`) VALUES 
          ('$user_class_id','$username','$sex','$password','$name_peple','$sname_peple','$year')";
    $result = mysqli_query($link2, $sql);
    
    if ($result) {
        header('Content-Type: application/json');
        echo json_encode(array('status' => 'success','message' => 'บันทึกข้อมูลเรียบร้อยแล้ว'));
    } else {
        header('Content-Type: application/json');
        $errors = "เกิดข้อผิดผลาดไม่สามารถบันทึกข้อมูลได้" . mysqli_error($link);
        echo json_encode(array('status' => 'danger','message' => $errors));
    }

Zerion Mini Shell 1.0