<?php //include_once('function.php'); //$objCon = connectDB(); include_once("../../../conapps/dbcon.php"); $objCon = mysqli_connect($servername,$username, $password, $dbname); // Check connection if ($objCon->connect_error) { die("Connection failed: " . $objCon->connect_error); } $data = $_POST; print_r($data); //$c_prefix = $data['c_prefix']; //$c_firstname = $data['c_firstname']; //$c_lastname = $data['c_lastname']; //$c_idcard = $data['c_idcard']; //$c_birthdate = $data['c_birthdate']; ////$c_mobile = $data['c_mobile']; //$c_detail = $data['c_detail']; //$c_image = 'noimg.png'; // default value $ref1=$data['ref1']; //หมายเลขบัตรประชาชน print_r($ref1); //ตรวจสอบข้อมูลซ้ำ $check = "SELECT * FROM tb_admissstudentymba WHERE ref1 = '".$ref1."' and codepro = 'YMBA26'" or die("Error:" . mysqli_error()); print_r($check); if (empty($f)){ echo "ไม่ซ้ำ เพิ่มได้"; $countnum = "SELECT COUNT(ref1) FROM tb_admissstudentymba WHERE ref1 = '".$ref1."' and codepro = 'YMBA26' "or die("Error:" . mysqli_error()); //print_r($countnum); $cresult1 = mysqli_query($objCon, $countnum); $cnum=mysqli_num_rows($cresult1); //print_r($cnum); if($cnum > 0) { $cadmissnum = $countnum +1; }else{ //กรณีเป็นค่าแรก $cadmissnum = 1; } print_r($cadmissnum); $ref2=$data['ref2']; //$admissnum=$data['admissnum']; $codepro = 'YMBA26'; $yearb ='22565';//2/2565 $numberc = "000000"+(string)$cadmissnum; $admissnum= $codepro."-".$yearb.$numberc; $idadreg=2; $ref2=$idadreg.$data['phonenumber'].$yearb.$numberc; //idadreg+phonenumber+ภาคที่สมัคร+ปีที่สมัคร+running $titlenamethai=$data['cap']; $thainame=$data['thainame']; $surname=$data['surname']; $titlenameeng=$data['cap']; $firstname=$data['firstname']; $lastname=$data['lastname']; $birthday=$data['date1']."-".$data['month1']."-".$data['yearhbd']; $age=$data['age']; $nationality=$data['nationality']; $religion=$data['religion']; $namedad=$data['namedad']; $namemom=$data['namemom']; $occupationdad=$data['occupationdad']; $occupationmom=$data['occupationmom']; $address3=$data['address3']; $phone=$data['phone']; $fax=$data['fax']; $email=$data['email']; $line=$data['line']; $address1=$data['address1']; $address2=$data['address2']; $time1=$data['time1']; $schollanduni1=$data['schollanduni1']; $namep1=$data['namep1']; $obj1=$data['obj1']; $gpa1=$data['gpa1']; $time2=$data['time2']; $schollanduni2=$data['schollanduni2']; $namep2=$data['namep2']; $obj2=$data['obj2']; $gpa2=$data['gpa2']; $time3=$data['time3']; $schollanduni3=$data['schollanduni3']; $namep3=$data['namep3']; $obj3=$data['obj3']; $gpa3=$data['gpa3']; $time4=$data['time4']; $schollanduni4=$data['schollanduni4']; $namep4=$data['namep4']; $obj4=$data['obj4']; $gpa4=$data['gpa4']; $address4=$data['address4']; $wyear1=$data['wyear1']; $position1=$data['position1']; $type1=$data['type1']; $wplance1=$data['wplance1']; $wyear2=$data['wyear2']; $position2=$data['position2']; $type2=$data['type2']; $wplance2=$data['wplance2']; $wyear3=$data['wyear3']; $position3=$data['position3']; $type3=$data['type3']; $wplance3=$data['wplance3']; $samana=$data['samana']; $image='noimg.png'; // default value $output_dir = 'images'; // folder if (!is_array($_FILES["image"]["name"])) { $exts = explode('.', $_FILES["image"]["name"]); $ext = $exts[count($exts) - 1]; // get ext image ex. jpeg, jpg, png $fileName = date("YmdHis") . '_' . randomString() . "." . $ext; if (file_exists($output_dir . $fileName)) { $fileName = $fileName = date("YmdHis") . '_' . randomString() . "." . $ext; } $c_image = $fileName; // set image value @move_uploaded_file($_FILES["image"]["tmp_name"], $output_dir . '/' . $fileName); } print_r($numberc); echo "numberc :".$numberc; echo "admissnum :".$admissnum; echo "ref2 :".$ref2; echo "c_image".$c_image; echo "birthday".$birthday; "INSERT INTO tb_admissstudentymba( `idstymba`, `ref1`, `ref2`, `admissnum`, `titlenamethai`, `thainame`, `surname`, `titlenameeng`, `firstname`, `lastname`, `birthday`, `age`, `nationality`, `religion`, `namedad`, `namemom`, `occupationdad`, `occupationmom`, `address3`, `phone`, `fax`, `email`, `line`, `address1`, `address2`, `time1`, `schollanduni1`, `namep1`, `obj1`, `gpa1`, `time2`, `schollanduni2`, `namep2`, `obj2`, `gpa2`, `time3`, `schollanduni3`, `namep3`, `obj3`, `gpa3`, `time4`, `schollanduni4`, `namep4`, `obj4`, `gpa4`, `address4`, `wyear1`, `position1`, `type1`, `wplance1`, `wyear2`, `position2`, `type2`, `wplance2`, `wyear3`, `position3`, `type3`, `wplance3`, `samana`, `image` ) VALUES ( NULL, '$ref1', '$ref2', '$admissnum', '$titlenamethai', '$thainame', '$surname', '$titlenameeng', '$firstname', '$lastname', '$birthday', '$age', '$nationality', '$religion', '$namedad', '$namemom', '$occupationdad', '$occupationmom', '$address3', '$phonenumber', '$fax', '$email', '$line', '$address1', '$address2', '$time1', '$schollanduni1', '$namep1', '$obj1', '$gpa1', '$time2', '$schollanduni2', '$namep2', '$obj2', '$gpa2', '$time3', '$schollanduni3', '$namep3', '$obj3', '$gpa3', '$time4', '$schollanduni4', '$namep4', '$obj4', '$gpa4', '$address4', '$wyear1', '$position1', '$type1', '$wplance1', '$wyear2', '$position2', '$type2', '$wplance2', '$wyear3', '$position3', '$type3', '$wplance3', '$samana', '$image' )"; /* if ($conn->multi_query($strSQL) === TRUE) { // echo "New records created successfully"; //} else { echo "Error: " . $strSQL. "<br>" . $conn->error; }*/ $query = mysqli_query($objCon, $strSQL); $fquery = mysqli_fetch_assoc($query); //$objQuery = mysqli_query($objCon, $strSQL) or die(mysqli_error($objCon)); if ($query) { echo '<script>alert("เพิ่มข้อมูลแล้ว");window.location="index.php";</script>'; } else { echo '<script>alert("พบข้อผิดพลาด");window.location="create.php";</script>'; } }else{ echo "ซ้ำ เพิ่มไม่ได้"; } ?>