<?php session_start(); include_once("../../../conapps/dbcon.php"); //เชื่อม var include_once("varpro.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); $ref1=$data['ref1']; //$procode=$_SESSION['procode']; //$idproem=$_SESSION['idproem']; //$idadreg=$_SESSION['idadreg']; //$codepay=$_SESSION['codepay']; //$idproem=$data['idproem']; //echo("idproem".$idproem); //echo("procode".$procode); //echo("idadreg".$idadreg); //echo("codepay".$codepay); //ตรวจสอบหมายเลขบัตรประจำตัวประชาชนซ้ำหรือไม่ $check = "SELECT * FROM tb_appemployee tbem WHERE tbem.cardnumber = '".$ref1."' and tbem.procode='".$procode."' and tbem.idproem='".$idproem."' and tbem.idadreg = '".$idadreg."' " or die("Error:" . mysqli_error()); //print_r($check ); $qcheck = mysqli_query($objCon, $check ); $fcheck = mysqli_fetch_assoc($qcheck); if (empty($fcheck)){ //echo "ไม่ซ้ำ เพิ่มได้"; //นับจำนวนผู้สมัครสอบทั้งหมด กี่คน $countnum = "SELECT * FROM tb_appemployee WHERE procode='".$procode."' and idproem='".$idproem."' and idadreg = '".$idadreg."' "or die("Error:" . mysqli_error()); //print_r($countnum); $cresult1 = mysqli_query($objCon, $countnum); $cnum=mysqli_num_rows($cresult1); //print_r($cnum); //$count1=$cresult1; if($cnum > 0) { $cadmissnum = $cnum +1; }else{ //กรณีเป็นค่าแรก $cadmissnum = 1; } //$procode = 'EM66'; //$codepay ='01';//รหัสชำระเงิน $yearb ='266';// ภาค2/65 $amount=300.00; //ค่าสมัครสอบแข่งขัน //$numberc = "000000"+$cadmissnum; $numberc = sprintf("%'.04d", $cadmissnum); $emnumber= $procode."-".$yearb.$numberc;//เลขที่ใบสมัคร //$idadreg=5; $phonenumber=$data['phonenumber']; $ref2=$idadreg.$phonenumber.$yearb.$numberc.$codepay; $count = $cnum; //ตรวจสอบว่ามีเลข ref2 ซ้ำหรือไม่ เพื่อทำการเพิ่ม ข้อมูล ที่ตาราง tb_qrapiem //$idproject = 33; $checkqrapi = "SELECT * FROM tb_qrapicp WHERE ref2 = '".$ref2."' and idproject ='".$idproem."' and idadreg = '".$idadreg."'" or die("Error:" . mysqli_error()); $cqrapi = mysqli_query($objCon, $checkqrapi ); $fcqrapi = mysqli_fetch_assoc($cqrapi); if (empty($fcqrapi)){ //echo "เพิ่มข้อมูล"; //}else{ //echo '<script>alert("พบข้อผิดพลาด ระบบมีข้อมูลแล้ว");window.location="insert_appemployee.php";</script>'; // } $glname = $data['glname'] ; //รับค่า idtitle และ idtitleeng $cap = $data['cap']; $idtitlethai =$cap; $idtitleeng = $cap; $thainame = $data['thainame']; $surname = $data['surname']; $firstname = $data['firstname']; $lastname = $data['lastname']; //$idproem = 1; $gender = $data['gender'] ; $birthday=$data['date1']."-".$data['month1']."-".$data['yearhbd']; $ethnicity=$data['ethnicity']; $nationality=$data['nationality']; $mstatus=$data['mstatus']; $namedad=$data['namedad']; $namemom=$data['namemom']; $positionsought=$data['positionsought']; $department=$data['department']; $hnumber=$data['hnumber']; $vnumber=$data['vnumber']; $vname=$data['vname']; $soi=$data['soi']; $road=$data['road']; $subdistrict=$data['subdistrict']; $district=$data['district']; $province=$data['province']; $zipcode=$data['zipcode']; $phonenumber=$data['phonenumber']; $email=$data['email']; $bdobtained=$data['bdobtained']; $bmajor=$data['bmajor']; $bgpa=$data['bgpa']; $buniversity=$data['buniversity']; $byeargbe=$data['byeargbe']; $bcountry=$data['bcountry']; $mdobtained=$data['mdobtained']; $mmajor=$data['mmajor']; $mgpa=$data['mgpa']; $muniversity=$data['muniversity']; $myeargbe=$data['myeargbe']; $mcountry=$data['mcountry']; $ddobtained=$data['ddobtained']; $dmajor=$data['dmajor']; $dgpa=$data['dgpa']; $duniversity=$data['duniversity']; $dyeargbe=$data['dyeargbe']; $dcountry=$data['dcountry']; $odobtained=$data['odobtained']; $omajor=$data['omajor']; $ogpa=$data['ogpa']; $ouniversity=$data['ouniversity']; $oyeargbe=$data['oyeargbe']; $ocountry=$data['ocountry']; $empreemployer3=$data['empreemployer3']; $emposition3=$data['emposition3']; $emfromdate3=$data['emfromdate3']; $emtodate3=$data['emtodate3']; $emreasonleav3=$data['emreasonleav3']; $empreemployer2=$data['empreemployer2']; $emposition2=$data['emposition2']; $emfromdate2=$data['emfromdate2']; $emtodate2=$data['emtodate2']; $emreasonleav2=$data['emreasonleav2']; $empreemployer1=$data['empreemployer1']; $emposition1=$data['emposition1']; $emfromdate1=$data['emfromdate1']; $emtodate1=$data['emtodate1']; $emreasonleav1=$data['emreasonleav1']; $languageskills1=$data['languageskills1']; $speak1=$data['speak1']; $read1=$data['read1']; $write1=$data['write1']; $languageskills2=$data['languageskills2']; $speak2=$data['speak2']; $read2=$data['read2']; $write2=$data['write2']; $computerskill=$data['computerskill']; $academicex=$data['academicex']; $otherex=$data['otherex']; $statuspay='รอชำระเงิน'; //$dateapp =date("Y-m-d"); $dateapp = date("d")."-".date("m")."-".(date("Y")+543); $timeapp =date("h:i:sa"); $amount2=0.00; //idqrapi สุดท้าย //$maxqra = "SELECT max(`idqrcomcode`) maxid FROM `tb_qrcompcode` "or die("Error:" . mysqli_error()); /*$maxqra = "SELECT max(`idqrapi`) maxid FROM `tb_qrapicp` "or die("Error:" . mysqli_error()); $cmaxqra = mysqli_query($objCon, $maxqra); $cnumz = mysqli_fetch_assoc($cmaxqra); $numz=$cnumz["maxid"];*/ $numzz=$numberc; $mastertime= "ZRUEE2311262400" ;//กำหนดวันที่สุดท้ายที่ให้ชำระเงิน $timepay= $mastertime.$idadreg.$numzz;//'ZRUEE2303222400ZZZZZ' //$c_image = 'noimg.png'; // default value //$mastertime= "ZRUEE2303222400" ;//กำหนดวันที่สุดท้ายที่ให้ชำระเงิน //$timepay= $mastertime.$idadreg.$numzz;//'ZRUEE2303222400ZZZZZ' //$c_image = 'noimg.png'; // default value $strSQL = "INSERT INTO `tb_appemployee` (`idem`,`cardnumber`,`ref2`,`glname`,`emnumber`,`count`,`yearb`,`procode`,`codepay`,`amount`,`idtitlethai`, `thainame`,`surname`,`idtitleeng`,`firstname`,`lastname`,`gender`,`birthday`,`ethnicity`,`nationality`,`mstatus`,`namedad`,`namemom`,`positionsought`,`department`,`hnumber`,`vnumber`,`vname`,`soi`,`road`,`subdistrict`,`district`,`province`,`zipcode`,`phonenumber`,`email`,`bdobtained`,`bmajor`,`bgpa`,`buniversity`,`byeargbe`,`bcountry`,`mdobtained`,`mmajor`,`mgpa`,`muniversity`,`myeargbe`,`mcountry`,`ddobtained`,`dmajor`,`dgpa`,`duniversity`,`dyeargbe`,`dcountry`,`odobtained`,`omajor`,`ogpa`,`ouniversity`,`oyeargbe`,`ocountry`,`empreemployer3`,`emposition3`,`emfromdate3`,`emtodate3`,`emreasonleav3`,`empreemployer2`,`emposition2`,`emfromdate2`,`emtodate2`,`emreasonleav2`,`empreemployer1`,`emposition1`,`emfromdate1`,`emtodate1`,`emreasonleav1`,`languageskills1`,`speak1`,`read1`,`write1`,`languageskills2`,`speak2`,`read2`,`write2`,`computerskill`,`academicex`,`otherex`,`dateapp`,`timeapp`,`idadreg`,`idproem`) VALUES (NULL,'$ref1','$ref2','$glname','$emnumber',$count,'$yearb','$procode','$codepay','$amount',$idtitlethai,'$thainame','$surname',$idtitleeng,'$firstname','$lastname','$gender','$birthday','$ethnicity','$nationality','$mstatus','$namedad','$namemom','$positionsought','$department','$hnumber','$vnumber','$vname','$soi','$road','$subdistrict','$district','$province','$zipcode','$phonenumber','$email','$bdobtained','$bmajor','$bgpa','$buniversity','$byeargbe','$bcountry','$mdobtained','$mmajor','$mgpa','$muniversity','$myeargbe','$mcountry','$ddobtained','$dmajor','$dgpa','$duniversity','$dyeargbe','$dcountry','$odobtained','$omajor','$ogpa','$ouniversity','$oyeargbe','$ocountry','$empreemployer3','$emposition3','$emfromdate3','$emtodate3','$emreasonleav3','$empreemployer2','$emposition2','$emfromdate2','$emtodate2','$emreasonleav2','$empreemployer1','$emposition1','$emfromdate1','$emtodate1','$emreasonleav1','$languageskills1','$speak1','$read1','$write1','$languageskills2','$speak2','$read2','$write2','$computerskill','$academicex','$otherex','$dateapp','$timeapp',$idadreg,$idproem)"; //print_r($strSQL); $q = mysqli_query($objCon, $strSQL); $f = mysqli_fetch_assoc($q); //เพิ่มข้อมูล qr tb_qrcompcode /*$qrsql = "INSERT INTO `tb_qrcompcode` (`idqrcomcode`,`ref1`,`ref2`,`amount`,`status`,`statusqrcode`,`dstatus`,`time`,`num`, `receiptnum`, `qrtextname`,`idadreg`,`idproem`) VALUES (NULL,'$ref1','$ref2','$amount','','$statusqrcode', '', '', '', '', '',$idadreg,$idproem)";*/ //$qrapi = mysqli_query($objCon, $qrsql); //$fqrapi = mysqli_fetch_assoc($qrapi); //$objQuery = mysqli_query($objCon, $strSQL) or die(mysqli_error($objCon)); /*INSERT INTO `tb_qrapicp` (`idqrapi`, `ref1`, `ref2`, `ref3`, `payername`, `payerbank`, `bankref`, `amount`, `amount2`, `statusamount`, `status`, `statuspay`, `dstatus`, `time`, `num`, `receiptnum`, `qrtextname`, `timepay`, `idadreg`, `idproject`) VALUES (NULL, '$ref1', '$ref2', '', '', '', '', '$amount', '$amount2', '', '', '$statuspay', '', '', '', '', '', '$timepay', '$idadreg', '$idproem');*/ // print_r($qrsql); if ($q) { //เพิ่มข้อมูล tb_qrapicp $qrsql = "INSERT INTO `tb_qrapicp` (`idqrapi`, `ref1`, `ref2`, `ref3`, `payername`, `payerbank`, `bankref`, `amount`, `amount2`, `statusamount`, `status`, `statuspay`, `dstatus`, `time`, `num`, `receiptnum`, `qrtextname`, `timepay`, `idadreg`, `idproject`) VALUES (NULL, '$ref1', '$ref2', '', '', '', '', '$amount', '$amount2', '', '', '$statuspay', '', '', '', '', '', '$timepay', '$idadreg', '$idproem')"; $qrapi = mysqli_query($objCon, $qrsql); $fqrapi = mysqli_fetch_assoc($qrapi); echo '<script>alert("เพิ่มข้อมูลแล้ว");window.location="https://instructors.ru.ac.th/application/admission/appemployee/login/loginappem.php";</script>'; } else { echo '<script>alert("พบข้อผิดพลาด");window.location="insertappemTest.php";</script>'; //print_r($strSQL); //print_r($qrsql); //print_r($q); //print_r($numzz); //print_r($numz); } //กรณี REF2 ซ้ำ }else{ //echo '<script>alert("พบข้อผิดพลาด ระบบมีข้อมูลแล้ว");window.location="insert_appemployee.php";</script>'; //echo "Error: " . $strSQL . "<br>" . $objCon->error; echo '<script>alert("พบข้อผิดพลาด ระบบมีข้อมูลแล้ว");window.location="insertappemTest.php";</script>'; } }else{ echo '<script>alert("มีข้อมูลในระบบแล้ว");window.location="insertappemTest.php";</script>'; } ?>