Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > อยากใช้ swal เมื่อ form action แล้ว ให้แสดง swal ทำอย่างไรครับ



 

อยากใช้ swal เมื่อ form action แล้ว ให้แสดง swal ทำอย่างไรครับ

 



Topic : 136093



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์




ถ้าหากใช้ <button type="submit" ฟอร์มมันก็จะไม่ตรวจ required
และเราจะใช้ swal ได้อย่างไร เพื่อแสดงผลว่า ส่งข้อมูลไปยัง databate เรียบร้อยแล้ว
มีแนวทางอย่างไรบ้างครับ

Form.php
<form action="sql/reg/insert_reg.php" id="reg_form" method="POST">
							 	<h2> <span class="badge badge-info">1.</span> <b>แผนการเรียน</b> </h2>
									<div class="row">
											<div class="form-group col-xl-6 col-xs-12">
												<label for="class_student">ระดับชั้น <text class="text-danger"> *</text> </label>
												<select class="form-control" name="class_student" id="class" required>
												<option value="" disabled selected hidden>กรุณาเลือกระดับชั้น</option>
												<option value="1" >มัธยมศึกษาปีที่ 1</option>
												<option value="4" >มัธยมศึกษาปีที่ 4</option>
											</select>
											</div>

											<div class="form-group col-xl-6 col-xs-12">
												<label for="edutype_student">เขตพื้นที่ <text class="text-danger"> *</text> </label>
												<select class="form-control" name="edutype_student" required>
												<option disabled selected hidden>กรุณาเลือกเขตพื้นที่</option>
												<option>ในเขตพื้นที่บริการ</option>
												<option>นอกเขตพื้นที่บริการ</option>
											</select>
											</div>
									</div>

									<div class="row">

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan_student">แผนการเรียน (อันดับ 1) <text class="text-danger"> *</text> </label>
											<select class="form-control"  id="eduplan" name="eduplan_student" required>
											<option selected disabled> กรุณาเลือกแผนการเรียน </option>
											</select>
										</div>
									

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan2_student">แผนการเรียน (อันดับ 2) <text class="text-danger"> *</text> </label>
											<select class="form-control"  id="eduplan2" name="eduplan2_student"  required>
											<option selected disabled> กรุณาเลือกแผนการเรียน </option>
										</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan3_student">แผนการเรียน (อันดับ 3) <text class="text-danger"> *</text> </label>
											<select class="form-control" id="eduplan3" name="eduplan3_student" required>
											<option value="" selected disabled> กรุณาเลือกแผนการเรียน </option>
											</select>
										</div>
									</div>

							 <hr>
							 <h2> <span class="badge badge-info">2.</span> <b>ข้อมูลบุคคล</b> </h2>

								<div class="row">

										<div class="form-group col-xl-6 col-xs-12">
											<label for="idcard_student">เลขประจำตัวประชาชน <text class="text-danger"> *</text> </label> 
											<input type="text" class="form-control" id="idcard_s" name="idcard_student" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค" required>
											 
										</div>

										<div class="form-group col-xl-6 col-xs-12">
											<label for="birthday_student">วันเกิด <text class="text-danger"> *</text> </label>
											<input type="date" class="form-control" name="birthday_student" placeholder="วัน/เดือน/ปี" required>
											<small class="form-text text-muted">กรุณากรอกเป็นปี ค.ศ. (iOS กรอกเป็น พ.ศ.)</small>
										</div>
								</div>

							 <hr>
							 <h2> <span class="badge badge-info">3.</span> <b>ข้อมูลพื้นฐาน</b> </h2>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="titlename_student">คำนำหน้า <text class="text-danger"> *</text> </label>
										<select class="form-control" name="titlename_student" required>
											<option disabled selected hidden>กรุณาเลือกคำนำหน้า</option>
											<option>เด็กชาย</option>
											<option>เด็กหญิง</option>
											<option>นาย</option>
											<option>นางสาว</option>
										</select>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="fristname_student">ชื่อ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="fristname_student" placeholder="ชื่อ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="lastname_student">นามสกุล <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="lastname_student" placeholder="นามสกุล" required>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="race_student">เชื้อชาติ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="race_student" placeholder="เชื้อชาติ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="nationality_student">สัญชาติ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="nationality_student" placeholder="สัญชาติ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="religious_student">ศาสนา <text class="text-danger"> *</text> </label>
										<select class="form-control" name="religious_student" required>
											<option disabled selected hidden>กรุณาเลือกศาสนา</option>
											<option>พุทธ</option>
											<option>คริสต์</option>
											<option>อิสลาม</option>
											<option>ซิกส์</option>
											<option>พราหมณ์/ฮินดู</option>
										</select>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="ban_number_student">บ้านเลขที่ <text class="text-danger"> *</text></label>
										<input type="text" class="form-control" name="ban_number_student" placeholder="บ้านเลขที่" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="moo_student">หมู่ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="moo_student" placeholder="หมู่" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="mooban_student">หมู่บ้าน</label>
										<input type="text" class="form-control" name="mooban_student" placeholder="หมู่บ้าน">
									</div>
								</div>
								

								<div class="row">
									<?php
									$sql_prov = "SELECT * FROM `provinces`";
									$query_prov = mysqli_query($con, $sql_prov);
									if (false === $query_prov) {
										die(mysqli_error($con));
									}
									?>

									<div class="form-group col-xl-3 col-xs-12">
										<label for="sub_district">ตำบล <text class="text-danger"> *</text> </label>
										<select class="form-control" name="sub_district_student" id="districts" required>
										<option selected disabled> กรุณาเลือกตำบล</option>
										</select>
									</div>
								

									<div class="form-group col-xl-3 col-xs-12">
										<label for="amphures_student">อำเภอ <text class="text-danger"> *</text> </label>
										<select class="form-control" name="amphures_student" id="amphures" required>
										<option selected disabled> กรุณาเลือกอำเภอ</option>
										</select>
									</div>

									<div class="form-group col-xl-3 col-xs-12">
										<label for="province_student">จังหวัด <text class="text-danger"> *</text> </label>
										<select class="form-control" name="province_student" id="provinces" required>
											<option disabled selected value="">กรุณาเลือกจังหวัด</option>
											<?php foreach ($query_prov as $value_prov) { ?>
												<option value="<?=$value_prov['id']?>"><?=$value_prov['name_th']?></option>
											<?php } ?>
										</select>
									</div>				

									<div class="form-group col-xl-3 col-xs-12">
										<label for="zip_code_student">รหัสไปษณีย์ <text class="text-danger"> *</text> </label>
										<input type="text" name="zip_code_student" id="zip_code" class="form-control" required>
									</div>

								</div>

								<div class="row">

									<div class="form-group col-xl-6 col-xs-12">
										<label for="h_tel_student">โทรศัพท์บ้าน </label>
										<input type="tel" class="form-control" name="h_tel_student" placeholder="โทรศัพท์บ้าน" >
									</div>

									<div class="form-group col-xl-6 col-xs-12">
										<label for="tel_student">โทรศัพท์มือถือ</label>
										<input type="tel" class="form-control" name="tel_student" placeholder="โทรศัพท์มือถือ">
									</div>

								</div>

								<hr>
							 <h2> <span class="badge badge-info">4.</span> <b>ข้อมูลการศึกษา</b> </h2>

								<div class="row">
									<div class="form-group col-xl-6 col-xs-12 ">
										<label for="eduold_student">ระดับการศึกษา <text class="text-danger"> *</text> </label>
										<select class="form-control" id="eduold" name="eduold_student" required>
										<option selected disabled hidden> กรุณาเลือกระดับการศึกษา</option>
										</select>
									</div>

									<div class="form-group col-xl-6 col-xs-12 ">
										<label for="school_student">จากโรงเรียน <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="school_student" placeholder="จากโรงเรียน" required>
									</div>

								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="school_amphures_student">อำเภอ <text class="text-danger"> *</text> </label>
										<input class="form-control" name="school_amphures_student" placeholder="อำเภอ" required></input>
									</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="school_province_student">จังหวัด <text class="text-danger"> *</text> </label>
											<input class="form-control" name="school_province_student" placeholder="จังหวัด" required></input>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname-stu">ผลการเรียน <text class="text-danger"> *</text></label>
											<input type="text" class="form-control" name="score_student" placeholder="ผลการเรียน" required>
										</div>
								</div>

							 <hr>
							 <h2> <span class="badge badge-info">5.</span> <b>ข้อมูลบิดา</b> </h2>


								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="titlename_father">คำนำหน้า <text class="text-danger"> *</text> </label>
										<select class="form-control" name="titlename_father" required>
											<option disabled selected hidden>กรุณาระบุ</option>
											<option>นาย</option>
											<option>นาง</option>
											<option>นางสาว</option>
										</select>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="fristname_father">ชื่อ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="fristname_father" placeholder="ชื่อ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="lastname_father">นามสกุล <text class="text-danger"> *</text></label>
										<input type="text" class="form-control" name="lastname_father" placeholder="นามสกุล" required>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="work_father">อาชีพ</label>
										<input type="text" class="form-control" name="work_father" placeholder="อาชีพ" >
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="location_work_father">สถานที่ทำงาน</label>
										<input type="text" class="form-control" name="location_work_father" placeholder="สถานที่ทำงาน" >
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="tel_father">เบอร์มือถือ</label>
										<input type="text" class="form-control" name="tel_father" placeholder="เบอร์มือถือ">
									</div>
								</div>						


							<hr>
							 <h2> <span class="badge badge-info">6.</span> <b>ข้อมูลมารดา</b> </h2>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="titlename_mother">คำนำหน้า <text class="text-danger"> *</text> </label>
											<select class="form-control" name="titlename_mother" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>นาย</option>
												<option>นาง</option>
												<option>นางสาว</option>
											</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="fristname_mother">ชื่อ <text class="text-danger"> *</text> </label>
											<input type="text" class="form-control" name="fristname_mother" placeholder="ชื่อ" required>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname_mother">นามสกุล <text class="text-danger"> *</text> </label>
											<input type="text" class="form-control" name="lastname_mother" placeholder="นามสกุล" required>
										</div>
									</div>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="work_mother">อาชีพ</label>
											<input type="text" class="form-control" name="work_mother" placeholder="อาชีพ" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="location_work_mother">สถานที่ทำงาน</label>
											<input type="text" class="form-control" name="location_work_mother" placeholder="สถานที่ทำงาน" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="tel_mother">เบอร์มือถือ</label>
											<input type="text" class="form-control" name="tel_mother" placeholder="เบอร์มือถือ" >
										</div>
									</div>		
									

									<hr>
							 <h2> <span class="badge badge-info">7.</span> <b>ข้อมูลผู้ปกครอง</b> </h2>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="titlename_parent">คำนำหน้า <text class="text-danger"> *</text>  </label>
											<select class="form-control" name="titlename_parent" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>นาย</option>
												<option>นาง</option>
												<option>นางสาว</option>
											</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="fristname_parent">ชื่อ <text class="text-danger"> *</text>  </label>
											<input type="text" class="form-control" name="fristname_parent" placeholder="ชื่อ" required>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname_parent">นามสกุล <text class="text-danger"> *</text>  </label>
											<input type="text" class="form-control" name="lastname_parent" placeholder="นามสกุล" required>
										</div>
									</div>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="work_parent">อาชีพ</label>
											<input type="text" class="form-control" name="work_parent" placeholder="อาชีพ" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="loaction_work_parent">สถานที่ทำงาน</label>
											<input type="text" class="form-control" name="loaction_work_parent" placeholder="สถานที่ทำงาน" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="tel_parent">เบอร์มือถือ</label>
											<input type="text" class="form-control" name="tel_parent" placeholder="เบอร์มือถือ" >
										</div>
									</div>

									<hr>
							 <h2> <span class="badge badge-info">8.</span> <b>ข้อมูลทั่วไป</b> </h2>
									<div class="row">

										<div class="form-group col">
										<label for="select_parent_student">นักเรียนอาศัยอยู่กับ <text class="text-danger"> *</text> </label>
											<select class="form-control" name="select_parent_student" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>บิดา</option>
												<option>มารดา</option>
												<option>ปู่</option>
												<option>ย่า</option>
												<option>ตา</option>
												<option>ยาย</option>
												<option>พี่ชาย</option>
												<option>พี่สาว</option>
											</select>
										</div>
									</div>
										
								<div class="text-center pt-3">
									<input type="checkbox" required> ข้าพเจ้าขอยืนยันว่าข้อมูลที่กรอกไป เป็นความจริงทุกประการ <br>
									<button type="submit" class="btn btn-primary mt-3">ลงทะเบียน</button>
								</div>
							<form>


Insert_reg.php
<?php
require('../../connect.php');

if(isset($_POST['edu_reg']) ) {

    // 1. - 5
    $class_student = mysqli_real_escape_string($con,$_POST['class_student']);
    $edutype_student = mysqli_real_escape_string($con,$_POST['edutype_student']);
    $eduplan_student = mysqli_real_escape_string($con,$_POST['eduplan_student']);
    $eduplan2_student = mysqli_real_escape_string($con,$_POST['eduplan2_student']);
    $eduplan3_student = mysqli_real_escape_string($con,$_POST['eduplan3_student']);

    //2. - 2
    $idcard_student = mysqli_real_escape_string($con,$_POST['idcard_student']);
    $birthday_student = mysqli_real_escape_string($con,$_POST['birthday_student']);

    //3. - 14
    $titlename_student = mysqli_real_escape_string($con,$_POST['titlename_student']);
    $fristname_student = mysqli_real_escape_string($con,$_POST['fristname_student']);
    $lastname_student = mysqli_real_escape_string($con,$_POST['lastname_student']);
    $race_student = mysqli_real_escape_string($con,$_POST['race_student']);
    $nationality_student = mysqli_real_escape_string($con,$_POST['nationality_student']);
    $ban_number_student = mysqli_real_escape_string($con,$_POST['ban_number_student']);
    $moo_student = mysqli_real_escape_string($con,$_POST['moo_student']);
    $mooban_student = mysqli_real_escape_string($con,$_POST['mooban_student']);
    $sub_district_student = mysqli_real_escape_string($con,$_POST['sub_district_student']);
    $amphures_student = mysqli_real_escape_string($con,$_POST['amphures_student']);
    $province_student = mysqli_real_escape_string($con,$_POST['province_student']);
    $zip_code_student = mysqli_real_escape_string($con,$_POST['zip_code_student']);
    $h_tel_student = mysqli_real_escape_string($con,$_POST['h_tel_student']);
    $tel_student = mysqli_real_escape_string($con,$_POST['tel_student']);

    //4. - 5
    $eduold_student = mysqli_real_escape_string($con,$_POST['eduold_student']);
    $school_student = mysqli_real_escape_string($con,$_POST['school_student']);
    $school_amphures_student= mysqli_real_escape_string($con,$_POST['school_amphures_student']);
    $school_province_student = mysqli_real_escape_string($con,$_POST['school_province_student']);
    $score_student = mysqli_real_escape_string($con,$_POST['score_student']);

    //5. - 6
    $titlename_father = mysqli_real_escape_string($con,$_POST['titlename_father']);
    $lastname_father = mysqli_real_escape_string($con,$_POST['lastname_father']);
    $fristname_father = mysqli_real_escape_string($con,$_POST['fristname_father']);
    $work_father = mysqli_real_escape_string($con,$_POST['work_father']);
    $location_work_father = mysqli_real_escape_string($con,$_POST['location_work_father']);
    $tel_father = mysqli_real_escape_string($con,$_POST['tel_father']);

    //6. - 6
    $titlename_mother = mysqli_real_escape_string($con,$_POST['titlename_mother']);
    $fristname_mother = mysqli_real_escape_string($con,$_POST['fristname_mother']);
    $lastname_mother = mysqli_real_escape_string($con,$_POST['lastname_mother']);
    $work_mother = mysqli_real_escape_string($con,$_POST['work_mother']);
    $location_work_mother = mysqli_real_escape_string($con,$_POST['location_work_mother']);
    $tel_mother = mysqli_real_escape_string($con,$_POST['tel_mother']);

    //7. - 6
    echo $_POST['titlename_parent'];
    $titlename_parent = mysqli_real_escape_string($con,$_POST['titlename_parent']);
    $fristname_parent = mysqli_real_escape_string($con,$_POST['fristname_parent']);
    $lastname_parent = mysqli_real_escape_string($con,$_POST['lastname_parent']);
    $work_parent = mysqli_real_escape_string($con,$_POST['work_parent']);
    $loaction_work_parent = mysqli_real_escape_string($con,$_POST['loaction_work_parent']);
    $tel_parent = mysqli_real_escape_string($con,$_POST['tel_parent']);

    //8. - 1
    $select_parent_student = mysqli_real_escape_string($con,$_POST['select_parent_student']);

    
    $query_reg= "INSERT INTO `student` VALUES('', '$class_student','$edutype_student','$eduplan_student','$eduplan2_student','$eduplan3_student' 
    ,'$idcard_student','$birthday_student'
    ,'$titlename_student','$fristname_student','$lastname_student','$race_student','$nationality_student','$ban_number_student','$moo_student','$mooban_student','$sub_district_student','$amphures_student','$province_student','$zip_code_student','$h_tel_student','$tel_student'
    ,'$eduold_student','$school_student','$school_amphures_student','$school_province_student','$score_student'
    ,'$titlename_father','$lastname_father','$fristname_father','$work_father','$location_work_father','$tel_father','$titlename_mother','$fristname_mother','$lastname_mother','$work_mother','$location_work_mother','$tel_mother'
    ,'$titlename_parent','$fristname_parent','$lastname_parent','$work_parent','$loaction_work_parent','$tel_parent'
    ,'$select_parent_student')";

$result_reg = mysqli_query($con, $query_reg);

if (false === $result_reg) {
    die(mysqli_error($con));
}




echo '<script>';
//echo 'location.replace("../../reg.php");';
echo '</script>';
}

else echo 'error';
?>




Tag : PHP, MySQL, HTML, CSS, HTML5









ประวัติการแก้ไข
2021-04-29 17:45:56
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2021-04-29 17:45:14 By : jgogo01 View : 3502 Reply : 48
 

 

No. 1



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


Code (PHP)
<!-- Ajax Send Form-->
<script>
$("#submit_reg").click(function(){
	//1
    var class_student = $("#class_student").val();
    var edutype_student = $("#edutype_student").val();
	var eduplan_student = $("#eduplan_student").val();
	var eduplan2_student = $("#eduplan2_student").val();
	var eduplan3_student = $("#eduplan3_student").val();

	//2
	var idcard_student = $("#idcard_student").val();
	var birthday_student = $("#birthday_student").val();

	//3	
	var titlename_student = $("#titlename_student").val();
	var fristname_student = $("#fristname_student").val();
	var lastname_student = $("#lastname_student").val();
	var race_student = $("#race_student").val();
	var nationality_student = $("#nationality_student").val();
	var religious_student = $("#religious_student").val();
	var ban_number_student = $("#ban_number_student").val();
	var moo_student = $("#moo_student").val();
	var sub_district_student = $("#sub_district_student").val();
	var amphures_student = $("#amphures_student").val();
	var province_student = $("#province_student").val();
	var zip_code_student = $("#zip_code_student").val();
	var h_tel_student = $("#h_tel_student").val();
	var tel_student = $("#tel_student").val();

	//4
	var eduold_student = $("#eduold_student").val();
	var school_student = $("#school_student").val();
	var sub_district_student = $("#sub_district_student").val();
	var school_amphures_student = $("#school_amphures_student").val();
	var school_province_student = $("#school_province_student").val();
	var score_student = $("#score_student").val();

	//5
	var titlename_father = $("#titlename_father").val();
	var fristname_father = $("#fristname_father").val();
	var lastname_father = $("#lastname_father").val();
	var work_father = $("#work_father").val();
	var location_work_father = $("#location_work_father").val();
	var tel_father = $("#tel_father").val();

	//6
	var titlename_mother = $("#titlename_mother").val();
	var fristname_mother = $("#fristname_mother").val();
	var lastname_mother = $("#lastname_mother").val();
	var work_mother = $("#work_mother").val();
	var location_work_mother = $("#location_work_mother").val();
	var tel_mother = $("#tel_mother").val();

	//7
	var titlename_parent = $("#titlename_parent").val();
	var fristname_parent = $("#fristname_parent").val();
	var lastname_parent = $("#lastname_parent").val();
	var work_parent = $("#work_parent").val();
	var loaction_work_parent = $("#loaction_work_parent").val();
	var tel_parent = $("#tel_parent").val();	

	//8
	var select_parent_student = $("#select_parent_student").val();	
	
		$.ajax({
            method:'POST',
            url:'sql/reg/insert_reg.php',
            data: {class_student:class_student, edutype_student:edutype_student, eduplan_student:eduplan_student, eduplan2_student:eduplan2_student, eduplan3_student:eduplan3_student,

			idcard_student:idcard_student, birthday_student:birthday_student,

			titlename_student:titlename_student, fristname_student:fristname_student, lastname_student:lastname_student, race_student:race_student, nationality_student:nationality_student,
			religious_student:religious_student, ban_number_student:ban_number_student, moo_student:moo_student, sub_district_student:sub_district_student, amphures_student:amphures_student, 
			province_student:province_student, zip_code_student:zip_code_student, h_tel_student:h_tel_student, tel_student:tel_student,

			eduold_student:eduold_student, school_student:school_student, sub_district_student:sub_district_student, school_amphures_student:school_amphures_student, school_province_student:school_province_student,
			score_student:score_student,
			
			titlename_father:titlename_father, fristname_father:fristname_father, lastname_father:lastname_father, work_father:work_father, location_work_father:location_work_father, tel_father:tel_father,

			titlename_mother:titlename_mother, fristname_mother:fristname_mother, lastname_mother:lastname_mother, work_mother:work_mother, location_work_mother:location_work_mother, tel_mother:tel_mother,

			titlename_parent:titlename_parent, fristname_parent:fristname_parent, lastname_parent:lastname_parent, work_parent:work_parent, loaction_work_parent:loaction_work_parent, tel_parent:tel_parent,

			select_parent_student:select_parent_student
		
			},

            success:function(data){
				alert('Hello');
				swal("Good job!", "You clicked the button!", {
						icon : "success",
						buttons: {        			
							confirm: {
								className : 'btn btn-success'
							}
						},
					});
            },

            error:function(data){
       		alert("error occured"); //===Show Error Message====
			}
       })

});
</script>



ตอนนี้ทำแบบนี้ครับแต่ alert swal ยังไม่ออกมาครับ








ประวัติการแก้ไข
2021-04-30 13:44:18
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-29 22:38:37 By : jgogo01
 


 

No. 2



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


swal format อย่างย่อ
swal( "title", "message", "type[success|error|info|....]");


ที่คุณใช้ผมไม่เคยใช้
หรือจะจะเต็มรูปแปป (บางส่วน
Code (JavaScript)
swal({
  title: 'title สามารถใช้ tag html',
  html: 'เนื้อหา สามารถใช้ tag html',
  onOpen:()=>{
     // function เมื่อโหลด จะให้ทำอะไรบ้าง
  }
});



หา document อ่านซะหน่อยก็ดีนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 08:28:49 By : Chaidhanan
 

 

No. 3



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-04-30 08:28:49
รายละเอียดของการตอบ ::

swal ตัวนี้ ก็เอามาจาก doc ครับ

ผมลองใส่ alert ดูก็ไม่ขึ้นครับ

**เพิ่มเติมครับ **
ajax ไม่ส่งข้อมูลแบบ post ครับ แต่ส่งแบบ get แทนครับ
แต่ข้อมูลส่งไปยังฐานข้อมูลครับ




ประวัติการแก้ไข
2021-04-30 13:40:51
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 13:16:29 By : jgogo01
 


 

No. 4



โพสกระทู้ ( 4,720 )
บทความ ( 8 )



สถานะออฟไลน์


Quote:
ajax ไม่ส่งข้อมูลแบบ post ครับ แต่ส่งแบบ get แทนครับ


ajax ก็ method: 'POST' แล้วมันจะส่งแบบ get ได้ยังไง?

Quote:
แต่ข้อมูลส่งไปยังฐานข้อมูลครับ

ส่วนรับข้อมูลก็ใช้แต่ $_POST แล้วข้อมูลมันจะรับเข้าไปฐานข้อมูลได้ยังไง?

ทำไมบอกอะไรเหมือนคนละเรื่องกับโค้ดเลย หรือโค้ดนี้เป็นงานอื่นหน้าอื่นที่ไม่เกี่ยวกับคำถาม?


ประวัติการแก้ไข
2021-04-30 15:26:50
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 15:26:10 By : mr.v
 


 

No. 5



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 4 เขียนโดย : mr.v เมื่อวันที่ 2021-04-30 15:26:10
รายละเอียดของการตอบ ::
ได้แล้วครับ ผมลืมใส่ type button ถ้าไม่ใส่มันส่งไปเป็น get จริง ๆ ครับ url มันเปลี่ยนเป็นแบบ get ครับ

แต่ผมจะให้ form เช็ค Req. ก่อนทำอย่างไรครับ
Button
	<button type="button" id="submit_reg" class="btn btn-primary mt-3">ลงทะเบียน</button>



script ajax
$("#submit_reg").click(function(){
	//1
    var class_student = $("#class_student").val();
    var edutype_student = $("#edutype_student").val();
	var eduplan_student = $("#eduplan_student").val();
	var eduplan2_student = $("#eduplan2_student").val();
	var eduplan3_student = $("#eduplan3_student").val();

	//2
	var idcard_student = $("#idcard_student").val();
	var birthday_student = $("#birthday_student").val();

	//3	
	var titlename_student = $("#titlename_student").val();
	var fristname_student = $("#fristname_student").val();
	var lastname_student = $("#lastname_student").val();
	var race_student = $("#race_student").val();
	var nationality_student = $("#nationality_student").val();
	var religious_student = $("#religious_student").val();
	var ban_number_student = $("#ban_number_student").val();
	var moo_student = $("#moo_student").val();
	var sub_district_student = $("#sub_district_student").val();
	var amphures_student = $("#amphures_student").val();
	var province_student = $("#province_student").val();
	var zip_code_student = $("#zip_code_student").val();
	var h_tel_student = $("#h_tel_student").val();
	var tel_student = $("#tel_student").val();

	//4
	var eduold_student = $("#eduold_student").val();
	var school_student = $("#school_student").val();
	var sub_district_student = $("#sub_district_student").val();
	var school_amphures_student = $("#school_amphures_student").val();
	var school_province_student = $("#school_province_student").val();
	var score_student = $("#score_student").val();

	//5
	var titlename_father = $("#titlename_father").val();
	var fristname_father = $("#fristname_father").val();
	var lastname_father = $("#lastname_father").val();
	var work_father = $("#work_father").val();
	var location_work_father = $("#location_work_father").val();
	var tel_father = $("#tel_father").val();

	//6
	var titlename_mother = $("#titlename_mother").val();
	var fristname_mother = $("#fristname_mother").val();
	var lastname_mother = $("#lastname_mother").val();
	var work_mother = $("#work_mother").val();
	var location_work_mother = $("#location_work_mother").val();
	var tel_mother = $("#tel_mother").val();

	//7
	var titlename_parent = $("#titlename_parent").val();
	var fristname_parent = $("#fristname_parent").val();
	var lastname_parent = $("#lastname_parent").val();
	var work_parent = $("#work_parent").val();
	var loaction_work_parent = $("#loaction_work_parent").val();
	var tel_parent = $("#tel_parent").val();	

	//8
	var select_parent_student = $("#select_parent_student").val();	
	
		$.ajax({
			url: "sql/reg/insert_reg.php",
       		method: "POST",
            data: {class_student:class_student, edutype_student:edutype_student, eduplan_student:eduplan_student, eduplan2_student:eduplan2_student, eduplan3_student:eduplan3_student,

			idcard_student:idcard_student, birthday_student:birthday_student,

			titlename_student:titlename_student, fristname_student:fristname_student, lastname_student:lastname_student, race_student:race_student, nationality_student:nationality_student,
			religious_student:religious_student, ban_number_student:ban_number_student, moo_student:moo_student, sub_district_student:sub_district_student, amphures_student:amphures_student, 
			province_student:province_student, zip_code_student:zip_code_student, h_tel_student:h_tel_student, tel_student:tel_student,

			eduold_student:eduold_student, school_student:school_student, sub_district_student:sub_district_student, school_amphures_student:school_amphures_student, school_province_student:school_province_student,
			score_student:score_student,
			
			titlename_father:titlename_father, fristname_father:fristname_father, lastname_father:lastname_father, work_father:work_father, location_work_father:location_work_father, tel_father:tel_father,

			titlename_mother:titlename_mother, fristname_mother:fristname_mother, lastname_mother:lastname_mother, work_mother:work_mother, location_work_mother:location_work_mother, tel_mother:tel_mother,

			titlename_parent:titlename_parent, fristname_parent:fristname_parent, lastname_parent:lastname_parent, work_parent:work_parent, loaction_work_parent:loaction_work_parent, tel_parent:tel_parent,

			select_parent_student:select_parent_student
		
			},

            success:function(data){
				swal("ลงทะเบียบสำเร็จ!", "กรุณาอัปโหลดเอกสารเพิ่มเติม", {
						icon : "success",
						buttons: {        			
							confirm: {
								text: "ตกลง",
								className : 'btn btn-success'
							}
						},
					});
				
            },

            error:function(data){
       		alert("error occured") //===Show Error Message====
			}
       })

});
</script>



ประวัติการแก้ไข
2021-04-30 16:06:21
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 16:00:01 By : jgogo01
 


 

No. 6



โพสกระทู้ ( 4,720 )
บทความ ( 8 )



สถานะออฟไลน์


ถ้าดัก $('#submit_reg').click มันจะไปดักเฉพาะปุ่มเมื่อคลิก ถ้าผู้ใช้กด enter มันก็ไม่เข้าเงื่อนไข

ควรดักที่ $('#reg_form').on('submit', function(event) {
// code
});
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 16:28:17 By : mr.v
 


 

No. 7



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 6 เขียนโดย : mr.v เมื่อวันที่ 2021-04-30 16:28:17
รายละเอียดของการตอบ ::
ขอบคุณมากครับผม

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 16:28:53 By : jgogo01
 


 

No. 8



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


น่าจะเปิด browser inspect ดู error วามันเออเร่อร์อะไรนะครับ

ส่วนอันนี้เป็น document ตอนนี้มัน version 10 แล้ว ลองดู version ใหม่ๆ ดูนะครับ
อันนี้ตัวอย่าง v7 เวอร์ชั่นสุดท้ายที่ใช้ แค่ swal()
https://sweetalert2.github.io/v7.html

ส่วน v8 + จะเป็น swal.fire();

เมื่อกี้ลองเอาไปวางใน netbean มีตัวแปรซ้ำซ้อน ลองเปลี่ยน วิธีกำหนดตัวแปร ดูครับ

เช่น

Code (JavaScript)
var ar = {
   aaa: $('#aaa').val(),
   bbb: $('#bbb').val()
};
// เวลาใช้ร่วมกับ ajax
$.ajax({url: 'xxxx.com', type: 'post', data: ar,
  success: result=>{
    //
  }, error: (jqxhr, exception)=>{
     //
  }
})

ปล.
สังเกต ผมใช้ type: post ไม่ได้ใช้ method: post คำสั่งนี้ผมไม่เคยใช้ อาจจะคนละ version
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 16:57:47 By : Chaidhanan
 


 

No. 9



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 8 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-04-30 16:57:47
รายละเอียดของการตอบ ::
ยังไง swal ก็ยังไม่ขึ้นครับ

แต่ข้อมูลเข้า db ปกติครับ หรือจะเป็นเพราะกรอกข้อมูลไม่ครบไหมครับ เพราะ form ผมมีบางช่องไม่ได้บังคับกรอกครับ
บน บราวเซอร์ไม่ขึ้น error ใด ๆ ครับ

ปล. ผมลองใช้ทั้ง method / type ส่งข้อมูลได้ทั้งคู่ครับผม
ที่ผมใช้ method เพราะดูอ้างอิงจาก doc เว็บครับ

ถ้าใช้ วิธีนี้ swal ขึ้นปกติครับ
$("#submit_reg").click(function(){
}


ajax
<script>
$('#reg_form').on('submit', function(event) {

	var data_edu = {
	//1
    class_student : $("#class_student").val(),
     edutype_student : $("#edutype_student").val(),
	 eduplan_student : $("#eduplan_student").val(),
	 eduplan2_student : $("#eduplan2_student").val(),
	 eduplan3_student : $("#eduplan3_student").val(),

	//2
	 idcard_student : $("#idcard_student").val(),
	 birthday_student : $("#birthday_student").val(),

	//3	
	 titlename_student : $("#titlename_student").val(),
	 fristname_student : $("#fristname_student").val(),
	 lastname_student : $("#lastname_student").val(),
	 race_student : $("#race_student").val(),
	 nationality_student : $("#nationality_student").val(),
	 religious_student : $("#religious_student").val(),
	 ban_number_student : $("#ban_number_student").val(),
	 moo_student : $("#moo_student").val(),
	 sub_district_student : $("#sub_district_student").val(),
	 amphures_student : $("#amphures_student").val(),
	 province_student : $("#province_student").val(),
	 zip_code_student : $("#zip_code_student").val(),
	 h_tel_student : $("#h_tel_student").val(),
	 tel_student : $("#tel_student").val(),

	//4
	 eduold_student : $("#eduold_student").val(),
	 school_student : $("#school_student").val(),
	 sub_district_student : $("#sub_district_student").val(),
	 school_amphures_student : $("#school_amphures_student").val(),
	 school_province_student : $("#school_province_student").val(),
	 score_student : $("#score_student").val(),

	//5
	 titlename_father : $("#titlename_father").val(),
	 fristname_father : $("#fristname_father").val(),
	 lastname_father : $("#lastname_father").val(),
	 work_father : $("#work_father").val(),
	 location_work_father : $("#location_work_father").val(),
	 tel_father : $("#tel_father").val(),

	//6
	 titlename_mother : $("#titlename_mother").val(),
	 fristname_mother : $("#fristname_mother").val(),
	 lastname_mother : $("#lastname_mother").val(),
	 work_mother : $("#work_mother").val(),
	 location_work_mother : $("#location_work_mother").val(),
	 tel_mother : $("#tel_mother").val(),

	//7
	 titlename_parent : $("#titlename_parent").val(),
	 fristname_parent : $("#fristname_parent").val(),
	 lastname_parent : $("#lastname_parent").val(),
	 work_parent : $("#work_parent").val(),
	 loaction_work_parent : $("#loaction_work_parent").val(),
	 tel_parent : $("#tel_parent").val(),	

	//8
	 select_parent_student : $("#select_parent_student").val()
	};

	$.ajax({url: 'sql/reg/insert_reg.php', type: 'POST', data: data_edu,
	success: result=>{

		swal("ลงทะเบียบสำเร็จ!", "กรุณาอัปโหลดเอกสารเพิ่มเติม", {
						icon : "success",
						buttons: {        			
							confirm: {
								text: "ตกลง",
								className : 'btn btn-success'
							}
						},
					});

	}, error: (jqxhr, exception)=>{
		alert('Error Ajax');
	}

	})

});
</script>




ประวัติการแก้ไข
2021-04-30 18:00:35
2021-04-30 18:03:15
2021-04-30 18:13:37
2021-04-30 18:38:06
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 17:55:48 By : jgogo01
 


 

No. 10



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


ผมว่าครั้งแรก javascript มัน error หาตัวแปรไม่พบ ทำให้หยุดการทำงาน มากกว่านะครับ เพราะผมลองเอาไปวางใน netbean
มันแจ้งตัวแปรไม่ได้ประกาศ

พอเปลี่ยนวิธี ทำให้ตัวแปรครบถ้วน ไม่เออเร่อร์ โปรแกรมเลยสามารถทำงานต่อไปได้

การตรวจหาเออเร่อร์ ของ javascript หลังจาก กด submit
ให้ คลิกขวา เลือก inspect แล้วเลือก tab console
ถ้ากดก่อน submit ก็จะไม่เห็น เออเร่อร์ เพราะมันยังไม่ได้ทำงาน
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 19:57:46 By : Chaidhanan
 


 

No. 11



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


ตัวอย่าง error callback ใน $.ajax()
Code (JavaScript)
    error:(jqXHR, exception)=>{
			var msg = '';
			if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.';
			} else if (jqXHR.status === 404) { msg = 'Requested page not found. [404]';
			} else if (jqXHR.status === 500) { msg = 'Internal Server Error [500].';
			} else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.';
			} else if (exception === 'timeout') { msg = 'Time out error.';
			} else if (exception === 'abort') { msg = 'Ajax request aborted.';
			} else { msg = 'Uncaught Error.\n' + jqXHR.responseText; }
			swal("error occured", msg, 'error'); //===Show Error Message====
		}


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 20:10:22 By : Chaidhanan
 


 

No. 12



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 11 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-04-30 20:10:22
รายละเอียดของการตอบ ::
เดี๋ยวไปลองไล่ error ดู ขอบคุณมากครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 21:11:54 By : jgogo01
 


 

No. 13



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 11 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-04-30 20:10:22
รายละเอียดของการตอบ ::
ไม่มี error ใด ๆ ออกมาครับ Inspect ดูก็ไม่มี error ใด ๆ ทั้งก่อน ละ หลังกด submit ครับ
ข้อมูลลง db ปกติครับ


โค้ดล่าสุด ครับ


form.php
							<form>
							 	<h2> <span class="badge badge-info">1.</span> <b>แผนการเรียน</b> </h2>
									<div class="row">
											<div class="form-group col-xl-6 col-xs-12">
												<label for="class_student">ระดับชั้น <text class="text-danger"> *</text> </label>
												<select class="form-control" name="class_student" id="class_student" required>
												<option value="" disabled selected hidden>กรุณาเลือกระดับชั้น</option>
												<option value="1" >มัธยมศึกษาปีที่ 1</option>
												<option value="4" >มัธยมศึกษาปีที่ 4</option>
											</select>
											</div>

											<div class="form-group col-xl-6 col-xs-12">
												<label for="edutype_student">เขตพื้นที่ <text class="text-danger"> *</text> </label>
												<select class="form-control" name="edutype_student" id="edutype_student" required>
												<option disabled selected hidden>กรุณาเลือกเขตพื้นที่</option>
												<option>ในเขตพื้นที่บริการ</option>
												<option>นอกเขตพื้นที่บริการ</option>
											</select>
											</div>
									</div>

									<div class="row">

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan_student">แผนการเรียน (อันดับ 1) <text class="text-danger"> *</text> </label>
											<select class="form-control"  id="eduplan_student" name="eduplan_student"  required>
											<option selected disabled> กรุณาเลือกแผนการเรียน </option>
											</select>
										</div>
									

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan2_student">แผนการเรียน (อันดับ 2) <text class="text-danger"> *</text> </label>
											<select class="form-control"  id="eduplan2_student" name="eduplan2_student" required>
											<option selected disabled> กรุณาเลือกแผนการเรียน </option>
										</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan3_student">แผนการเรียน (อันดับ 3) <text class="text-danger"> *</text> </label>
											<select class="form-control" id="eduplan3_student" name="eduplan3_student" required>
											<option value="" selected disabled> กรุณาเลือกแผนการเรียน </option>
											</select>
										</div>
									</div>

							 <hr>
							 <h2> <span class="badge badge-info">2.</span> <b>ข้อมูลบุคคล</b> </h2>

								<div class="row">

										<div class="form-group col-xl-6 col-xs-12">
											<label for="idcard_student">เลขประจำตัวประชาชน <text class="text-danger"> *</text> </label> 
											<input type="text" class="form-control" id="idcard_student" name="idcard_student" pattern="^[0-9]+$" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค" required>
										</div>

										<div class="form-group col-xl-6 col-xs-12">
											<label for="birthday_student">วันเกิด <text class="text-danger"> *</text> </label>
											<input type="date" class="form-control" id="birthday_student" name="birthday_student" placeholder="วัน/เดือน/ปี" required>
											<small class="form-text text-muted">กรุณากรอกเป็นปี ค.ศ. (iOS กรอกเป็น พ.ศ.)</small>
										</div>
								</div>

							 <hr>
							 <h2> <span class="badge badge-info">3.</span> <b>ข้อมูลพื้นฐาน</b> </h2>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="titlename_student">คำนำหน้า <text class="text-danger"> *</text> </label>
										<select class="form-control" id="titlename_student" name="titlename_student" required>
											<option disabled selected hidden>กรุณาเลือกคำนำหน้า</option>
											<option>เด็กชาย</option>
											<option>เด็กหญิง</option>
											<option>นาย</option>
											<option>นางสาว</option>
										</select>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="fristname_student">ชื่อ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" id="fristname_student" name="fristname_student" placeholder="ชื่อ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="lastname_student">นามสกุล <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" id="lastname_student" name="lastname_student" placeholder="นามสกุล" required>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="race_student">เชื้อชาติ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" id="race_student" name="race_student" placeholder="เชื้อชาติ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="nationality_student">สัญชาติ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" id="nationality_student" name="nationality_student" placeholder="สัญชาติ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="religious_student">ศาสนา <text class="text-danger"> *</text> </label>
										<select class="form-control" id="religious_student" name="religious_student" required>
											<option disabled selected hidden>กรุณาเลือกศาสนา</option>
											<option>พุทธ</option>
											<option>คริสต์</option>
											<option>อิสลาม</option>
											<option>ซิกส์</option>
											<option>พราหมณ์/ฮินดู</option>
										</select>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="ban_number_student">บ้านเลขที่ <text class="text-danger"> *</text></label>
										<input type="text" class="form-control" id="ban_number_student" name="ban_number_student" placeholder="บ้านเลขที่" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="moo_student">หมู่ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" id="moo_student" name="moo_student" placeholder="หมู่" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="mooban_student">หมู่บ้าน</label>
										<input type="text" class="form-control" id="mooban_student" name="mooban_student" placeholder="หมู่บ้าน">
									</div>
								</div>
								

								<div class="row">
									<?php
									$sql_prov = "SELECT * FROM `provinces`";
									$query_prov = mysqli_query($con, $sql_prov);
									if (false === $query_prov) {
										die(mysqli_error($con));
									}
									?>

									<div class="form-group col-xl-3 col-xs-12">
										<label for="sub_district">ตำบล <text class="text-danger"> *</text> </label>
										<select class="form-control" name="sub_district_student" id="sub_district_student" required>
										<option selected disabled> กรุณาเลือกตำบล</option>
										</select>
									</div>
								

									<div class="form-group col-xl-3 col-xs-12">
										<label for="amphures_student">อำเภอ <text class="text-danger"> *</text> </label>
										<select class="form-control" name="amphures_student" id="amphures_student" required>
										<option selected disabled> กรุณาเลือกอำเภอ</option>
										</select>
									</div>

									<div class="form-group col-xl-3 col-xs-12">
										<label for="province_student">จังหวัด <text class="text-danger"> *</text> </label>
										<select class="form-control" name="province_student" id="province_student" required>
											<option disabled selected value="">กรุณาเลือกจังหวัด</option>
											<?php foreach ($query_prov as $value_prov) { ?>
												<option value="<?=$value_prov['id']?>"><?=$value_prov['name_th']?></option>
											<?php } ?>
										</select>
									</div>				

									<div class="form-group col-xl-3 col-xs-12">
										<label for="zip_code_student">รหัสไปษณีย์ <text class="text-danger"> *</text> </label>
										<input type="text" name="zip_code_student" id="zip_code_student" class="form-control" required>
									</div>

								</div>

								<div class="row">

									<div class="form-group col-xl-6 col-xs-12">
										<label for="h_tel_student">โทรศัพท์บ้าน </label>
										<input type="tel" class="form-control" name="h_tel_student" id="h_tel_student" placeholder="โทรศัพท์บ้าน" >
									</div>

									<div class="form-group col-xl-6 col-xs-12">
										<label for="tel_student">โทรศัพท์มือถือ</label>
										<input type="tel" class="form-control" name="tel_student" id="tel_student" placeholder="โทรศัพท์มือถือ">
									</div>

								</div>

								<hr>
							 <h2> <span class="badge badge-info">4.</span> <b>ข้อมูลการศึกษา</b> </h2>

								<div class="row">
									<div class="form-group col-xl-6 col-xs-12 ">
										<label for="eduold_student">ระดับการศึกษา <text class="text-danger"> *</text> </label>
										<select class="form-control" id="eduold_student" name="eduold_student" required>
										<option selected disabled hidden> กรุณาเลือกระดับการศึกษา</option>
										</select>
									</div>

									<div class="form-group col-xl-6 col-xs-12 ">
										<label for="school_student">จากโรงเรียน <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="school_student" id="school_student" placeholder="จากโรงเรียน" required>
									</div>

								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="school_amphures_student">อำเภอ <text class="text-danger"> *</text> </label>
										<input class="form-control" name="school_amphures_student" id="school_amphures_student" placeholder="อำเภอ" required></input>
									</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="school_province_student">จังหวัด <text class="text-danger"> *</text> </label>
											<input class="form-control" name="school_province_student" id="school_province_student" placeholder="จังหวัด" required></input>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname-stu">ผลการเรียน <text class="text-danger"> *</text></label>
											<input type="text" class="form-control" name="score_student" id="score_student" placeholder="ผลการเรียน" required>
										</div>
								</div>

							 <hr>
							 <h2> <span class="badge badge-info">5.</span> <b>ข้อมูลบิดา</b> </h2>


								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="titlename_father">คำนำหน้า <text class="text-danger"> *</text> </label>
										<select class="form-control" name="titlename_father" id="titlename_father" required>
											<option disabled selected hidden>กรุณาระบุ</option>
											<option>นาย</option>
											<option>นาง</option>
											<option>นางสาว</option>
										</select>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="fristname_father">ชื่อ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control" name="fristname_father" id="fristname_father" placeholder="ชื่อ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="lastname_father">นามสกุล <text class="text-danger"> *</text></label>
										<input type="text" class="form-control" name="lastname_father" id="lastname_father" placeholder="นามสกุล" required>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="work_father">อาชีพ</label>
										<input type="text" class="form-control" name="work_father" id="work_father" placeholder="อาชีพ" >
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="location_work_father">สถานที่ทำงาน</label>
										<input type="text" class="form-control" name="location_work_father" id="location_work_father" placeholder="สถานที่ทำงาน" >
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="tel_father">เบอร์มือถือ</label>
										<input type="text" class="form-control" name="tel_father" id="tel_father" placeholder="เบอร์มือถือ">
									</div>
								</div>						


							 <hr>
							 <h2> <span class="badge badge-info">6.</span> <b>ข้อมูลมารดา</b> </h2>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="titlename_mother">คำนำหน้า <text class="text-danger"> *</text> </label>
											<select class="form-control" name="titlename_mother" id="titlename_mother" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>นาย</option>
												<option>นาง</option>
												<option>นางสาว</option>
											</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="fristname_mother">ชื่อ <text class="text-danger"> *</text> </label>
											<input type="text" class="form-control" id="fristname_mother" name="fristname_mother" placeholder="ชื่อ" required>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname_mother">นามสกุล <text class="text-danger"> *</text> </label>
											<input type="text" class="form-control" id="lastname_mother" name="lastname_mother" placeholder="นามสกุล" required>
										</div>
									</div>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="work_mother">อาชีพ</label>
											<input type="text" class="form-control" id="work_mother" name="work_mother" placeholder="อาชีพ" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="location_work_mother">สถานที่ทำงาน</label>
											<input type="text" class="form-control" id="location_work_mother" name="location_work_mother" placeholder="สถานที่ทำงาน" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="tel_mother">เบอร์มือถือ</label>
											<input type="text" class="form-control" id="tel_mother" name="tel_mother" placeholder="เบอร์มือถือ" >
										</div>
									</div>		
									

									<hr>
							 <h2> <span class="badge badge-info">7.</span> <b>ข้อมูลผู้ปกครอง</b> </h2>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="titlename_parent">คำนำหน้า <text class="text-danger"> *</text>  </label>
											<select class="form-control" name="titlename_parent" id="titlename_parent" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>นาย</option>
												<option>นาง</option>
												<option>นางสาว</option>
											</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="fristname_parent">ชื่อ <text class="text-danger"> *</text>  </label>
											<input type="text" class="form-control" name="fristname_parent" id="fristname_parent" placeholder="ชื่อ" required>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname_parent">นามสกุล <text class="text-danger"> *</text>  </label>
											<input type="text" class="form-control" name="lastname_parent" id="lastname_parent" placeholder="นามสกุล" required>
										</div>
									</div>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="work_parent">อาชีพ</label>
											<input type="text" class="form-control" name="work_parent" id="work_parent" placeholder="อาชีพ" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="loaction_work_parent">สถานที่ทำงาน</label>
											<input type="text" class="form-control" name="loaction_work_parent" id="loaction_work_parent" placeholder="สถานที่ทำงาน" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="tel_parent">เบอร์มือถือ</label>
											<input type="text" class="form-control" name="tel_parent" id="tel_parent" placeholder="เบอร์มือถือ" >
										</div>
									</div>

									<hr>
							 <h2> <span class="badge badge-info">8.</span> <b>ข้อมูลทั่วไป</b> </h2>
									<div class="row">

										<div class="form-group col">
										<label for="select_parent_student">นักเรียนอาศัยอยู่กับ <text class="text-danger"> *</text> </label>
											<select class="form-control" name="select_parent_student" id="select_parent_student" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>บิดา</option>
												<option>มารดา</option>
												<option>ปู่</option>
												<option>ย่า</option>
												<option>ตา</option>
												<option>ยาย</option>
												<option>พี่ชาย</option>
												<option>พี่สาว</option>
											</select>
										</div>
									</div>
										
								<div class="text-center pt-3">
									<input type="checkbox" required> ข้าพเจ้าขอยืนยันว่าข้อมูลที่กรอกไป เป็นความจริงทุกประการ <br>
									<button type="submit" class="btn btn-primary mt-3">ลงทะเบียน</button>
								</div>
							</form>


script.js
<script>
$('#reg_form').on('submit', function(event) {

	var data_edu = {
	//1
    class_student : $("#class_student").val(),
     edutype_student : $("#edutype_student").val(),
	 eduplan_student : $("#eduplan_student").val(),
	 eduplan2_student : $("#eduplan2_student").val(),
	 eduplan3_student : $("#eduplan3_student").val(),

	//2
	 idcard_student : $("#idcard_student").val(),
	 birthday_student : $("#birthday_student").val(),

	//3	
	 titlename_student : $("#titlename_student").val(),
	 fristname_student : $("#fristname_student").val(),
	 lastname_student : $("#lastname_student").val(),
	 race_student : $("#race_student").val(),
	 nationality_student : $("#nationality_student").val(),
	 religious_student : $("#religious_student").val(),
	 ban_number_student : $("#ban_number_student").val(),
	 moo_student : $("#moo_student").val(),
	 sub_district_student : $("#sub_district_student").val(),
	 amphures_student : $("#amphures_student").val(),
	 province_student : $("#province_student").val(),
	 zip_code_student : $("#zip_code_student").val(),
	 h_tel_student : $("#h_tel_student").val(),
	 tel_student : $("#tel_student").val(),

	//4
	 eduold_student : $("#eduold_student").val(),
	 school_student : $("#school_student").val(),
	 sub_district_student : $("#sub_district_student").val(),
	 school_amphures_student : $("#school_amphures_student").val(),
	 school_province_student : $("#school_province_student").val(),
	 score_student : $("#score_student").val(),

	//5
	 titlename_father : $("#titlename_father").val(),
	 fristname_father : $("#fristname_father").val(),
	 lastname_father : $("#lastname_father").val(),
	 work_father : $("#work_father").val(),
	 location_work_father : $("#location_work_father").val(),
	 tel_father : $("#tel_father").val(),

	//6
	 titlename_mother : $("#titlename_mother").val(),
	 fristname_mother : $("#fristname_mother").val(),
	 lastname_mother : $("#lastname_mother").val(),
	 work_mother : $("#work_mother").val(),
	 location_work_mother : $("#location_work_mother").val(),
	 tel_mother : $("#tel_mother").val(),

	//7
	 titlename_parent : $("#titlename_parent").val(),
	 fristname_parent : $("#fristname_parent").val(),
	 lastname_parent : $("#lastname_parent").val(),
	 work_parent : $("#work_parent").val(),
	 loaction_work_parent : $("#loaction_work_parent").val(),
	 tel_parent : $("#tel_parent").val(),	

	//8
	 select_parent_student : $("#select_parent_student").val()
	};

	$.ajax({url: 'sql/reg/insert_reg.php', type: 'POST', data: data_edu,
	success: result=>{

		swal("ลงทะเบียบสำเร็จ!", "กรุณาอัปโหลดเอกสารเพิ่มเติม", {
						icon : "success",
						buttons: {        			
							confirm: {
								text: "ตกลง",
								className : 'btn btn-success'
							}
						},
					});

		},   

	error:(jqXHR, exception)=>{
		var msg = '';
		if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.';
		} else if (jqXHR.status === 404) { msg = 'Requested page not found. [404]';
		} else if (jqXHR.status === 500) { msg = 'Internal Server Error [500].';
		} else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.';
		} else if (exception === 'timeout') { msg = 'Time out error.';
		} else if (exception === 'abort') { msg = 'Ajax request aborted.';
		} else { msg = 'Uncaught Error.\n' + jqXHR.responseText; }
		swal("error occured", msg, 'error'); //===Show Error Message====
	}

	});

});



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 21:22:22 By : jgogo01
 


 
Code (PHP)
if(isset($_POST['edu_reg']) ) {


ใน ajax เมธอด ไม่ได้ส่ง edu_reg ไปแล้วหน้า insert_reg มันจะเรียกใช้ mysqli_query() ได้อย่างไร แม้จะพึงใบบุญจาก <button type="submit" ก็ไม่น่าจะบันทึกลงฐานข้อมูล ให้ข้อมูลไม่ครบหรือไม่
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 21:52:06 By : พญามัจจุราช
 


 

No. 15



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 14 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-04-30 21:52:06
รายละเอียดของการตอบ ::
ในส่วนนี้ได้แก้ไขไปเรียบร้อยแล้วครับผม ไม่ได้เอาโค้ดมาให้ดูครับ

ผมได้ให้เช็คแค่ค่า idcard ครับ เขียนทั้งหมดคงไม่ไหว
Code (PHP)
if( isset($_POST["idcard_student"]) ){
}




ประวัติการแก้ไข
2021-04-30 22:05:53
2021-04-30 22:05:58
2021-04-30 22:06:49
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-04-30 22:02:07 By : jgogo01
 


 
ตอบความคิดเห็นที่ : 15 เขียนโดย : jgogo01 เมื่อวันที่ 2021-04-30 22:02:07
รายละเอียดของการตอบ ::
Code (JavaScript)
success: result=>{...}



result ถ้าไม่ได้ใช้ประโยชน์หรือแค่ล่อ response ว่างไว้ก็ได้

Code
success: () => {...}


เนื่องจาก swal มีหน้าที่แค่แจ้งเตือน ...แบบเข้าใจง่ายคือ alert() ในชุดงามตา

ดังนั้น วิธีเช็คว่า เป็นที่ swal หรือไม่ ลองใช้ alert() ...
ถ้า alert() ทำงาน แสดงว่า swal งอแง...ต้องเข้าอู่

จริงๆ เช็คจาก response ดีแล้ว

Code (PHP)
if( isset($_POST["idcard_student"]) ){...}
else echo 'error'; // ???


เหมือนจะอยู่นอก if ใช่หรือไม่ ...
แบบนี้ response ก็จะเป็น empty string
ถ้าต้องการส่งค่าหลับมายัง success option
ทำง่ายๆ ด้วย plain-text/html (ยังไม่ต้อง json)

Code (PHP)
if( isset($_POST["idcard_student"]) ){
    //...
    
    // ส่วนนี้ทำทดสอบไปก่อนค่อยมาศัลย...
    if (false === $result_reg) {  
        echo "error";  // ถ้าบันทึกล้มเหลว
        die(mysqli_error($con));
    } else {
        echo "success";  // ข้อความสำเร็จ
    }
}


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 00:59:38 By : พญามัจจุราช
 


 

No. 17



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


แนะนำเพิ่มเติม
tag input อันไหนที่ต้องการ POST ให้ใส่คลาส เช่น for-post เข้าไปด้วย

Code (PHP)
<input class="form-control for-post" name="aaa" value="aaa-test">
<input class="form-control for-post" name="bbb" value="bbb-test">
<script>
  var ar={};
  $('.for-post').each((i,o)=>{
      ar[o.name]=o.value;
  });
  $.ajax({url: 'xxxx.com', type: 'post', data: ar});



ประเภทออกแบบไว้แต่ต้นทำงานง่ายกว่า สั้นกว่า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 09:59:49 By : Chaidhanan
 


 

No. 18



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 16 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-01 00:59:38
รายละเอียดของการตอบ ::
ได้ลองใส่ alert แล้วครับ alert ไม่ออกเช่นกันครับ งงมาก

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 15:45:41 By : jgogo01
 


 

No. 19



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 17 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-05-01 09:59:49
รายละเอียดของการตอบ ::
ขอบคุณคำแนะนำดี ๆ มากครับ ^^

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 15:52:27 By : jgogo01
 


 

No. 20



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


โค้ดล่าสุดครับ
ตอนนี้ alert ยังไม่ออกใด ๆ ข้อมูลส่งลง db ปกติครับ

Form.php
							<form id="reg_form">
							 	<h2> <span class="badge badge-info">1.</span> <b>แผนการเรียน</b> </h2>
									<div class="row">
											<div class="form-group col-xl-6 col-xs-12">
												<label for="class_student">ระดับชั้น <text class="text-danger"> *</text> </label>
												<select class="form-control for-post" name="class_student" id="class_student" required>
												<option value="" disabled selected hidden>กรุณาเลือกระดับชั้น</option>
												<option value="1" >มัธยมศึกษาปีที่ 1</option>
												<option value="4" >มัธยมศึกษาปีที่ 4</option>
											</select>
											</div>

											<div class="form-group col-xl-6 col-xs-12">
												<label for="edutype_student">เขตพื้นที่ <text class="text-danger"> *</text> </label>
												<select class="form-control for-post" name="edutype_student" id="edutype_student" required>
												<option disabled selected hidden>กรุณาเลือกเขตพื้นที่</option>
												<option>ในเขตพื้นที่บริการ</option>
												<option>นอกเขตพื้นที่บริการ</option>
											</select>
											</div>
									</div>

									<div class="row">

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan_student">แผนการเรียน (อันดับ 1) <text class="text-danger"> *</text> </label>
											<select class="form-control for-post"  id="eduplan_student" name="eduplan_student"  required>
											<option selected disabled> กรุณาเลือกแผนการเรียน </option>
											</select>
										</div>
									

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan2_student">แผนการเรียน (อันดับ 2) <text class="text-danger"> *</text> </label>
											<select class="form-control for-post"  id="eduplan2_student" name="eduplan2_student" required>
											<option selected disabled> กรุณาเลือกแผนการเรียน </option>
										</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="eduplan3_student">แผนการเรียน (อันดับ 3) <text class="text-danger"> *</text> </label>
											<select class="form-control for-post" id="eduplan3_student" name="eduplan3_student" required>
											<option value="" selected disabled> กรุณาเลือกแผนการเรียน </option>
											</select>
										</div>
									</div>

							 <hr>
							 <h2> <span class="badge badge-info">2.</span> <b>ข้อมูลบุคคล</b> </h2>

								<div class="row">

										<div class="form-group col-xl-6 col-xs-12">
											<label for="idcard_student">เลขประจำตัวประชาชน <text class="text-danger"> *</text> </label> 
											<input type="text" class="form-control for-post" id="idcard_student" name="idcard_student" pattern="^[0-9]+$" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค" required>
										</div>

										<div class="form-group col-xl-6 col-xs-12">
											<label for="birthday_student">วันเกิด <text class="text-danger"> *</text> </label>
											<input type="date" class="form-control for-post" id="birthday_student" name="birthday_student" placeholder="วัน/เดือน/ปี" required>
											<small class="form-text text-muted">กรุณากรอกเป็นปี ค.ศ. (iOS กรอกเป็น พ.ศ.)</small>
										</div>
								</div>

							 <hr>
							 <h2> <span class="badge badge-info">3.</span> <b>ข้อมูลพื้นฐาน</b> </h2>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="titlename_student">คำนำหน้า <text class="text-danger"> *</text> </label>
										<select class="form-control for-post" id="titlename_student" name="titlename_student" required>
											<option disabled selected hidden>กรุณาเลือกคำนำหน้า</option>
											<option>เด็กชาย</option>
											<option>เด็กหญิง</option>
											<option>นาย</option>
											<option>นางสาว</option>
										</select>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="fristname_student">ชื่อ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control for-post" id="fristname_student" name="fristname_student" placeholder="ชื่อ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="lastname_student">นามสกุล <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control for-post" id="lastname_student" name="lastname_student" placeholder="นามสกุล" required>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="race_student">เชื้อชาติ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control for-post" id="race_student" name="race_student" placeholder="เชื้อชาติ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="nationality_student">สัญชาติ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control for-post" id="nationality_student" name="nationality_student" placeholder="สัญชาติ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="religious_student">ศาสนา <text class="text-danger"> *</text> </label>
										<select class="form-control for-post" id="religious_student" name="religious_student" required>
											<option disabled selected hidden>กรุณาเลือกศาสนา</option>
											<option>พุทธ</option>
											<option>คริสต์</option>
											<option>อิสลาม</option>
											<option>ซิกส์</option>
											<option>พราหมณ์/ฮินดู</option>
										</select>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="ban_number_student">บ้านเลขที่ <text class="text-danger"> *</text></label>
										<input type="text" class="form-control for-post" id="ban_number_student" name="ban_number_student" placeholder="บ้านเลขที่" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="moo_student">หมู่ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control for-post" id="moo_student" name="moo_student" placeholder="หมู่" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="mooban_student">หมู่บ้าน</label>
										<input type="text" class="form-control for-post" id="mooban_student" name="mooban_student" placeholder="หมู่บ้าน">
									</div>
								</div>
								

								<div class="row">
									<?php
									$sql_prov = "SELECT * FROM `provinces`";
									$query_prov = mysqli_query($con, $sql_prov);
									if (false === $query_prov) {
										die(mysqli_error($con));
									}
									?>

									<div class="form-group col-xl-3 col-xs-12">
										<label for="sub_district">ตำบล <text class="text-danger"> *</text> </label>
										<select class="form-control for-post" name="sub_district_student" id="sub_district_student" required>
										<option selected disabled> กรุณาเลือกตำบล</option>
										</select>
									</div>
								

									<div class="form-group col-xl-3 col-xs-12">
										<label for="amphures_student">อำเภอ <text class="text-danger"> *</text> </label>
										<select class="form-control for-post" name="amphures_student" id="amphures_student" required>
										<option selected disabled> กรุณาเลือกอำเภอ</option>
										</select>
									</div>

									<div class="form-group col-xl-3 col-xs-12">
										<label for="province_student">จังหวัด <text class="text-danger"> *</text> </label>
										<select class="form-control for-post" name="province_student" id="province_student" required>
											<option disabled selected value="">กรุณาเลือกจังหวัด</option>
											<?php foreach ($query_prov as $value_prov) { ?>
												<option value="<?=$value_prov['id']?>"><?=$value_prov['name_th']?></option>
											<?php } ?>
										</select>
									</div>				

									<div class="form-group col-xl-3 col-xs-12">
										<label for="zip_code_student">รหัสไปษณีย์ <text class="text-danger"> *</text> </label>
										<input type="text" name="zip_code_student" id="zip_code_student" class="form-control for-post" required>
									</div>

								</div>

								<div class="row">

									<div class="form-group col-xl-6 col-xs-12">
										<label for="h_tel_student">โทรศัพท์บ้าน </label>
										<input type="tel" class="form-control for-post" name="h_tel_student" id="h_tel_student" placeholder="โทรศัพท์บ้าน" >
									</div>

									<div class="form-group col-xl-6 col-xs-12">
										<label for="tel_student">โทรศัพท์มือถือ</label>
										<input type="tel" class="form-control for-post" name="tel_student" id="tel_student" pattern="^[0-9]+$" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค">
									</div>

								</div>

								<hr>
							 <h2> <span class="badge badge-info">4.</span> <b>ข้อมูลการศึกษา</b> </h2>

								<div class="row">
									<div class="form-group col-xl-6 col-xs-12 ">
										<label for="eduold_student">ระดับการศึกษา <text class="text-danger"> *</text> </label>
										<select class="form-control for-post" id="eduold_student" name="eduold_student" required>
										<option selected disabled hidden> กรุณาเลือกระดับการศึกษา</option>
										</select>
									</div>

									<div class="form-group col-xl-6 col-xs-12 ">
										<label for="school_student">จากโรงเรียน <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control for-post" name="school_student" id="school_student" placeholder="จากโรงเรียน" required>
									</div>

								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="school_amphures_student">อำเภอ <text class="text-danger"> *</text> </label>
										<input class="form-control for-post" name="school_amphures_student" id="school_amphures_student" placeholder="อำเภอ" required></input>
									</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="school_province_student">จังหวัด <text class="text-danger"> *</text> </label>
											<input class="form-control for-post" name="school_province_student" id="school_province_student" placeholder="จังหวัด" required></input>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname-stu">ผลการเรียน <text class="text-danger"> *</text></label>
											<input type="text" class="form-control for-post" name="score_student" id="score_student" pattern="^[0-9.]+$" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค" required>
										</div>
								</div>

							 <hr>
							 <h2> <span class="badge badge-info">5.</span> <b>ข้อมูลบิดา</b> </h2>


								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="titlename_father">คำนำหน้า <text class="text-danger"> *</text> </label>
										<select class="form-control for-post" name="titlename_father" id="titlename_father" required>
											<option disabled selected hidden>กรุณาระบุ</option>
											<option>นาย</option>
											<option>นาง</option>
											<option>นางสาว</option>
										</select>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="fristname_father">ชื่อ <text class="text-danger"> *</text> </label>
										<input type="text" class="form-control for-post" name="fristname_father" id="fristname_father" placeholder="ชื่อ" required>
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="lastname_father">นามสกุล <text class="text-danger"> *</text></label>
										<input type="text" class="form-control for-post" name="lastname_father" id="lastname_father" placeholder="นามสกุล" required>
									</div>
								</div>

								<div class="row">
									<div class="form-group col-xl-4 col-xs-12">
										<label for="work_father">อาชีพ</label>
										<input type="text" class="form-control for-post" name="work_father" id="work_father" placeholder="อาชีพ" >
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="location_work_father">สถานที่ทำงาน</label>
										<input type="text" class="form-control for-post" name="location_work_father" id="location_work_father" placeholder="สถานที่ทำงาน" >
									</div>

									<div class="form-group col-xl-4 col-xs-12">
										<label for="tel_father">เบอร์มือถือ</label>
										<input type="text" class="form-control for-post" name="tel_father" id="tel_father" pattern="^[0-9]+$" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค">
									</div>
								</div>						


							 <hr>
							 <h2> <span class="badge badge-info">6.</span> <b>ข้อมูลมารดา</b> </h2>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="titlename_mother">คำนำหน้า <text class="text-danger"> *</text> </label>
											<select class="form-control for-post" name="titlename_mother" id="titlename_mother" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>นาย</option>
												<option>นาง</option>
												<option>นางสาว</option>
											</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="fristname_mother">ชื่อ <text class="text-danger"> *</text> </label>
											<input type="text" class="form-control for-post" id="fristname_mother" name="fristname_mother" placeholder="ชื่อ" required>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname_mother">นามสกุล <text class="text-danger"> *</text> </label>
											<input type="text" class="form-control for-post" id="lastname_mother" name="lastname_mother" placeholder="นามสกุล" required>
										</div>
									</div>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="work_mother">อาชีพ</label>
											<input type="text" class="form-control for-post" id="work_mother" name="work_mother" placeholder="อาชีพ" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="location_work_mother">สถานที่ทำงาน</label>
											<input type="text" class="form-control for-post" id="location_work_mother" name="location_work_mother" placeholder="สถานที่ทำงาน" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="tel_mother">เบอร์มือถือ</label>
											<input type="text" class="form-control for-post" id="tel_mother" name="tel_mother" pattern="^[0-9]+$" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค">
										</div>
									</div>		
									

									<hr>
							 <h2> <span class="badge badge-info">7.</span> <b>ข้อมูลผู้ปกครอง</b> </h2>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="titlename_parent">คำนำหน้า <text class="text-danger"> *</text>  </label>
											<select class="form-control for-post" name="titlename_parent" id="titlename_parent" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>นาย</option>
												<option>นาง</option>
												<option>นางสาว</option>
											</select>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="fristname_parent">ชื่อ <text class="text-danger"> *</text>  </label>
											<input type="text" class="form-control for-post" name="fristname_parent" id="fristname_parent" placeholder="ชื่อ" required>
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="lastname_parent">นามสกุล <text class="text-danger"> *</text>  </label>
											<input type="text" class="form-control for-post" name="lastname_parent" id="lastname_parent" placeholder="นามสกุล" required>
										</div>
									</div>

									<div class="row">
										<div class="form-group col-xl-4 col-xs-12">
											<label for="work_parent">อาชีพ</label>
											<input type="text" class="form-control for-post" name="work_parent" id="work_parent" placeholder="อาชีพ" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="loaction_work_parent">สถานที่ทำงาน</label>
											<input type="text" class="form-control for-post" name="loaction_work_parent" id="loaction_work_parent" placeholder="สถานที่ทำงาน" >
										</div>

										<div class="form-group col-xl-4 col-xs-12">
											<label for="tel_parent">เบอร์มือถือ</label>
											<input type="text" class="form-control for-post" name="tel_parent" id="tel_parent" pattern="^[0-9]+$" placeholder="ตัวเลขเท่านั้น ห้ามมีขีด และวรรค" >
										</div>
									</div>

									<hr>
							 <h2> <span class="badge badge-info">8.</span> <b>ข้อมูลทั่วไป</b> </h2>
									<div class="row">

										<div class="form-group col">
										<label for="select_parent_student">นักเรียนอาศัยอยู่กับ <text class="text-danger"> *</text> </label>
											<select class="form-control for-post" name="select_parent_student" id="select_parent_student" required>
												<option disabled selected hidden>กรุณาระบุ</option>
												<option>บิดา</option>
												<option>มารดา</option>
												<option>ปู่</option>
												<option>ย่า</option>
												<option>ตา</option>
												<option>ยาย</option>
												<option>พี่ชาย</option>
												<option>พี่สาว</option>
											</select>
										</div>
									</div>
										
								<div class="text-center pt-3">
									<input type="checkbox" required> ข้าพเจ้าขอยืนยันว่าข้อมูลที่กรอกไป เป็นความจริงทุกประการ <br>
									<button type="submit" class="btn btn-primary mt-3">ลงทะเบียน</button>
								</div>
							</form>



ScriptAjax_SendDataForm
<script>
$('#reg_form').on('submit', function(event) {

	var data_edu={};
  $('.for-post').each((i,o)=>{
	data_edu[o.name]=o.value;
  });

	$.ajax({url: 'sql/reg/insert_reg.php', type: 'POST', data: data_edu,
	success: ()=>{
		alert('ลงทะเบียบสำเร็จ!');
		swal("ลงทะเบียบสำเร็จ!", "กรุณาอัปโหลดเอกสารเพิ่มเติม", {
						icon : "success",
						buttons: {        			
							confirm: {
								text: "ตกลง",
								className : 'btn btn-success'
							}
						},
					});

		},   

	error:(jqXHR, exception)=>{
		var msg = '';
		if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.';
		} else if (jqXHR.status === 404) { msg = 'Requested page not found. [404]';
		} else if (jqXHR.status === 500) { msg = 'Internal Server Error [500].';
		} else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.';
		} else if (exception === 'timeout') { msg = 'Time out error.';
		} else if (exception === 'abort') { msg = 'Ajax request aborted.';
		} else { msg = 'Uncaught Error.\n' + jqXHR.responseText; }
		swal("error occured", msg, 'error'); //===Show Error Message====
		alert(msg);
	}

	});

});
</script>



insert_reg.php
<?php
require('../../connect.php');

if(isset($_POST['idcard_student']) ){
    // 1. - 5
    $class_student = mysqli_real_escape_string($con,$_POST['class_student']);
    $edutype_student = mysqli_real_escape_string($con,$_POST['edutype_student']);
    $eduplan_student = mysqli_real_escape_string($con,$_POST['eduplan_student']);
    $eduplan2_student = mysqli_real_escape_string($con,$_POST['eduplan2_student']);
    $eduplan3_student = mysqli_real_escape_string($con,$_POST['eduplan3_student']);

    //2. - 2
    $idcard_student = mysqli_real_escape_string($con,$_POST['idcard_student']);
    $birthday_student = mysqli_real_escape_string($con,$_POST['birthday_student']);

    //3. - 14
    $titlename_student = mysqli_real_escape_string($con,$_POST['titlename_student']);
    $fristname_student = mysqli_real_escape_string($con,$_POST['fristname_student']);
    $lastname_student = mysqli_real_escape_string($con,$_POST['lastname_student']);
    $race_student = mysqli_real_escape_string($con,$_POST['race_student']);
    $nationality_student = mysqli_real_escape_string($con,$_POST['nationality_student']);
    $ban_number_student = mysqli_real_escape_string($con,$_POST['ban_number_student']);
    $moo_student = mysqli_real_escape_string($con,$_POST['moo_student']);
    $mooban_student = mysqli_real_escape_string($con,$_POST['mooban_student']);
    $sub_district_student = mysqli_real_escape_string($con,$_POST['sub_district_student']);
    $amphures_student = mysqli_real_escape_string($con,$_POST['amphures_student']);
    $province_student = mysqli_real_escape_string($con,$_POST['province_student']);
    $zip_code_student = mysqli_real_escape_string($con,$_POST['zip_code_student']);
    $h_tel_student = mysqli_real_escape_string($con,$_POST['h_tel_student']);
    $tel_student = mysqli_real_escape_string($con,$_POST['tel_student']);

    //4. - 5
    $eduold_student = mysqli_real_escape_string($con,$_POST['eduold_student']);
    $school_student = mysqli_real_escape_string($con,$_POST['school_student']);
    $school_amphures_student= mysqli_real_escape_string($con,$_POST['school_amphures_student']);
    $school_province_student = mysqli_real_escape_string($con,$_POST['school_province_student']);
    $score_student = mysqli_real_escape_string($con,$_POST['score_student']);

    //5. - 6
    $titlename_father = mysqli_real_escape_string($con,$_POST['titlename_father']);
    $lastname_father = mysqli_real_escape_string($con,$_POST['lastname_father']);
    $fristname_father = mysqli_real_escape_string($con,$_POST['fristname_father']);
    $work_father = mysqli_real_escape_string($con,$_POST['work_father']);
    $location_work_father = mysqli_real_escape_string($con,$_POST['location_work_father']);
    $tel_father = mysqli_real_escape_string($con,$_POST['tel_father']);

    //6. - 6
    $titlename_mother = mysqli_real_escape_string($con,$_POST['titlename_mother']);
    $fristname_mother = mysqli_real_escape_string($con,$_POST['fristname_mother']);
    $lastname_mother = mysqli_real_escape_string($con,$_POST['lastname_mother']);
    $work_mother = mysqli_real_escape_string($con,$_POST['work_mother']);
    $location_work_mother = mysqli_real_escape_string($con,$_POST['location_work_mother']);
    $tel_mother = mysqli_real_escape_string($con,$_POST['tel_mother']);

    //7. - 6
    $titlename_parent = mysqli_real_escape_string($con,$_POST['titlename_parent']);
    $fristname_parent = mysqli_real_escape_string($con,$_POST['fristname_parent']);
    $lastname_parent = mysqli_real_escape_string($con,$_POST['lastname_parent']);
    $work_parent = mysqli_real_escape_string($con,$_POST['work_parent']);
    $loaction_work_parent = mysqli_real_escape_string($con,$_POST['loaction_work_parent']);
    $tel_parent = mysqli_real_escape_string($con,$_POST['tel_parent']);

    //8. - 1
    $select_parent_student = mysqli_real_escape_string($con,$_POST['select_parent_student']);

    
    $query_reg= "INSERT INTO `student` VALUES('', '$class_student','$edutype_student','$eduplan_student','$eduplan2_student','$eduplan3_student' 
    ,'$idcard_student','$birthday_student'
    ,'$titlename_student','$fristname_student','$lastname_student','$race_student','$nationality_student','$ban_number_student','$moo_student','$mooban_student','$sub_district_student','$amphures_student','$province_student','$zip_code_student','$h_tel_student','$tel_student'
    ,'$eduold_student','$school_student','$school_amphures_student','$school_province_student','$score_student'
    ,'$titlename_father','$lastname_father','$fristname_father','$work_father','$location_work_father','$tel_father','$titlename_mother','$fristname_mother','$lastname_mother','$work_mother','$location_work_mother','$tel_mother'
    ,'$titlename_parent','$fristname_parent','$lastname_parent','$work_parent','$loaction_work_parent','$tel_parent'
    ,'$select_parent_student')";

    $result_reg = mysqli_query($con, $query_reg);

    if (false === $result_reg) {
        die(mysqli_error($con));
    }
    else echo 'success';
}
else echo 'error';

?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 15:58:04 By : jgogo01
 


 
ตอบความคิดเห็นที่ : 20 เขียนโดย : jgogo01 เมื่อวันที่ 2021-05-01 15:58:04
รายละเอียดของการตอบ ::
ทบทวนวิธีการใช้คำสั่ง if...else... ดีๆ

ทำแบบนั้นจะได้

Code
PHP Parse error: syntax error, unexpected 'if' (T_IF) in /.../xxx.php on line ...


ให้เลือกใช้อย่างใดอย่างหนึ่ง ...
ิexpression vs block statement ใช้ผสมกันไม่ได้
ทำให้ดูใน No.16 แล้ว

ที่ Ajax ไม่วิ่งกลับไปฝั่ง client เพราะโดนตัดตรง if

ผิดไวยากรณ์ 2 ชั้น ทั้งนอกและใน
if(...) { if (false === $result_reg) { die(mysqli_error($con)); } else echo 'success'; } else echo 'error';


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 17:48:39 By : พญามัจจุราช
 


 

No. 22



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 21 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-01 17:48:39
รายละเอียดของการตอบ ::
ขอบคุณมากครับ ลืมตรงนี้ไปเลย บางทีเขียนนาน ๆ ก็บันทอนสติครับ 55 ^^

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 17:56:14 By : jgogo01
 


 

No. 23



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 21 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-01 17:48:39
รายละเอียดของการตอบ ::
ได้แก้ไขแล้วครับ alert ยังไม่ออกมาเลยครับ

Code (Java)
<script>
$('#reg_form').on('submit', function(event) {

	var data_edu={};
  $('.for-post').each((i,o)=>{
	data_edu[o.name]=o.value;
  });

	$.ajax({url: 'sql/reg/insert_reg.php', type: 'POST', data: data_edu,
	success: ()=>{
		alert('ลงทะเบียบสำเร็จ!');
		swal("ลงทะเบียบสำเร็จ!", "กรุณาอัปโหลดเอกสารเพิ่มเติม", {
						icon : "success",
						buttons: {        			
							confirm: {
								text: "ตกลง",
								className : 'btn btn-success'
							}
						},
					});

		},   

	error:(jqXHR, exception)=>{
		var msg = '';
		if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.';
		} else if (jqXHR.status === 404) { msg = 'Requested page not found. [404]';
		} else if (jqXHR.status === 500) { msg = 'Internal Server Error [500].';
		} else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.';
		} else if (exception === 'timeout') { msg = 'Time out error.';
		} else if (exception === 'abort') { msg = 'Ajax request aborted.';
		} else { msg = 'Uncaught Error.\n' + jqXHR.responseText; }
		swal("error occured", msg, 'error'); //===Show Error Message====
		alert(msg);
	}

	});

});
</script>



Code (PHP)
<?php
require('../../connect.php');

if(isset($_POST['idcard_student']) ){
    // 1. - 5
    $class_student = mysqli_real_escape_string($con,$_POST['class_student']);
    $edutype_student = mysqli_real_escape_string($con,$_POST['edutype_student']);
    $eduplan_student = mysqli_real_escape_string($con,$_POST['eduplan_student']);
    $eduplan2_student = mysqli_real_escape_string($con,$_POST['eduplan2_student']);
    $eduplan3_student = mysqli_real_escape_string($con,$_POST['eduplan3_student']);

    //2. - 2
    $idcard_student = mysqli_real_escape_string($con,$_POST['idcard_student']);
    $birthday_student = mysqli_real_escape_string($con,$_POST['birthday_student']);

    //3. - 14
    $titlename_student = mysqli_real_escape_string($con,$_POST['titlename_student']);
    $fristname_student = mysqli_real_escape_string($con,$_POST['fristname_student']);
    $lastname_student = mysqli_real_escape_string($con,$_POST['lastname_student']);
    $race_student = mysqli_real_escape_string($con,$_POST['race_student']);
    $nationality_student = mysqli_real_escape_string($con,$_POST['nationality_student']);
    $ban_number_student = mysqli_real_escape_string($con,$_POST['ban_number_student']);
    $moo_student = mysqli_real_escape_string($con,$_POST['moo_student']);
    $mooban_student = mysqli_real_escape_string($con,$_POST['mooban_student']);
    $sub_district_student = mysqli_real_escape_string($con,$_POST['sub_district_student']);
    $amphures_student = mysqli_real_escape_string($con,$_POST['amphures_student']);
    $province_student = mysqli_real_escape_string($con,$_POST['province_student']);
    $zip_code_student = mysqli_real_escape_string($con,$_POST['zip_code_student']);
    $h_tel_student = mysqli_real_escape_string($con,$_POST['h_tel_student']);
    $tel_student = mysqli_real_escape_string($con,$_POST['tel_student']);

    //4. - 5
    $eduold_student = mysqli_real_escape_string($con,$_POST['eduold_student']);
    $school_student = mysqli_real_escape_string($con,$_POST['school_student']);
    $school_amphures_student= mysqli_real_escape_string($con,$_POST['school_amphures_student']);
    $school_province_student = mysqli_real_escape_string($con,$_POST['school_province_student']);
    $score_student = mysqli_real_escape_string($con,$_POST['score_student']);

    //5. - 6
    $titlename_father = mysqli_real_escape_string($con,$_POST['titlename_father']);
    $lastname_father = mysqli_real_escape_string($con,$_POST['lastname_father']);
    $fristname_father = mysqli_real_escape_string($con,$_POST['fristname_father']);
    $work_father = mysqli_real_escape_string($con,$_POST['work_father']);
    $location_work_father = mysqli_real_escape_string($con,$_POST['location_work_father']);
    $tel_father = mysqli_real_escape_string($con,$_POST['tel_father']);

    //6. - 6
    $titlename_mother = mysqli_real_escape_string($con,$_POST['titlename_mother']);
    $fristname_mother = mysqli_real_escape_string($con,$_POST['fristname_mother']);
    $lastname_mother = mysqli_real_escape_string($con,$_POST['lastname_mother']);
    $work_mother = mysqli_real_escape_string($con,$_POST['work_mother']);
    $location_work_mother = mysqli_real_escape_string($con,$_POST['location_work_mother']);
    $tel_mother = mysqli_real_escape_string($con,$_POST['tel_mother']);

    //7. - 6
    $titlename_parent = mysqli_real_escape_string($con,$_POST['titlename_parent']);
    $fristname_parent = mysqli_real_escape_string($con,$_POST['fristname_parent']);
    $lastname_parent = mysqli_real_escape_string($con,$_POST['lastname_parent']);
    $work_parent = mysqli_real_escape_string($con,$_POST['work_parent']);
    $loaction_work_parent = mysqli_real_escape_string($con,$_POST['loaction_work_parent']);
    $tel_parent = mysqli_real_escape_string($con,$_POST['tel_parent']);

    //8. - 1
    $select_parent_student = mysqli_real_escape_string($con,$_POST['select_parent_student']);

    
    $query_reg= "INSERT INTO `student` VALUES('', '$class_student','$edutype_student','$eduplan_student','$eduplan2_student','$eduplan3_student' 
    ,'$idcard_student','$birthday_student'
    ,'$titlename_student','$fristname_student','$lastname_student','$race_student','$nationality_student','$ban_number_student','$moo_student','$mooban_student','$sub_district_student','$amphures_student','$province_student','$zip_code_student','$h_tel_student','$tel_student'
    ,'$eduold_student','$school_student','$school_amphures_student','$school_province_student','$score_student'
    ,'$titlename_father','$lastname_father','$fristname_father','$work_father','$location_work_father','$tel_father','$titlename_mother','$fristname_mother','$lastname_mother','$work_mother','$location_work_mother','$tel_mother'
    ,'$titlename_parent','$fristname_parent','$lastname_parent','$work_parent','$loaction_work_parent','$tel_parent'
    ,'$select_parent_student')";

    $result_reg = mysqli_query($con, $query_reg);

    if (false === $result_reg) {  
        echo "error";  
        die(mysqli_error($con));
    } 
    
    else {
        echo "success"; 
    }
}


?>



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 18:47:08 By : jgogo01
 


 
Code (JavaScript)
	$('#reg_form').on('submit', function(event) {

		var data_edu={};
		 $('.for-post').each((i,o)=>{
		   data_edu[o.name]=o.value;
		 });
	   
		   $.ajax({ url: 'sql/reg/insert_reg.php',
					type: 'POST', 
					data: data_edu,})
				   .done(function(){
			   alert('ลงทะเบียบสำเร็จ!');
			   swal("ลงทะเบียบสำเร็จ!", "กรุณาอัปโหลดเอกสารเพิ่มเติม", {
							   icon : "success",
							   buttons: {        			
								   confirm: {
									   text: "ตกลง",
									   className : 'btn btn-success'
								   }
							   },
						   });
	   
			   })	   
			.fail(function(msg ){
				//var msg = '';
			   if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.';
			   } else if (jqXHR.status === 404) { msg = 'Requested page not found. [404]';
			   } else if (jqXHR.status === 500) { msg = 'Internal Server Error [500].';
			   } else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.';
			   } else if (exception === 'timeout') { msg = 'Time out error.';
			   } else if (exception === 'abort') { msg = 'Ajax request aborted.';
			   } else { msg = 'Uncaught Error.\n' + jqXHR.responseText; }
			   swal("error occured", msg, 'error'); //===Show Error Message====
			   alert(msg);
		   });
	   
	   });

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 19:19:05 By : มั่วๆ
 


 
Code (JavaScript)
		   $.ajax({ 
			   url: 'sql/reg/insert_reg.php',
				type: 'POST', 
				data: data_edu
			})
			.done(function(){
			   alert('ลงทะเบียบสำเร็จ!');
			})	   
			.fail(function(msg){
			   alert(msg);
		   });

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 19:24:30 By : มั่วๆ
 


 

No. 26



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 25 เขียนโดย : มั่วๆ เมื่อวันที่ 2021-05-01 19:24:30
รายละเอียดของการตอบ ::
ยังไม่ได้ครับ alert ไม่ออกครับ ไม่พบ error ใด ๆ ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 20:08:21 By : jgogo01
 


 
ลองเล่นกับ response data

Code (JavaScript)
success: (res)=>{
    alert(res);
   // อย่างอื่น comment ไปก่อน
}


ถ้ายังไม่มา เคลียร์หัวท้าย request ก่อนส่งกลับ

Code (PHP)
if( isset($_POST["idcard_student"]) ){
    ob_clean(); // บนสุดใน if
    //...
    if (false === $result_reg) { 
        echo "error";
        die(mysqli_error($con));
    } else {
        echo "success";
    }
    exit;  // ปิดท้าย
}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 20:29:55 By : พญามัจจุราช
 


 

No. 28



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


แน่นำ ตัวรับ request
Code (PHP)
<?php
require('../../connect.php');
if(isset($_POST['idcard_student']) ){
	$sql= ''; $ar=[];
	foreach($_POST as $k=>$val){
		$sql.=(str_len($sql<1)? 'INSERT INTO `student` set ' : ',') . $k;
		$ar[]=$val;
	}
	$stmt=$con->prepare($sql);
	$stmt->bind_param(str_repeat('s',count($ar)), ...$ar);
	$stmt->execute();
	if($stmt->errno>0) die( $stmt->error );
    echo 'success';
}else echo 'error';
?>


ลองศึกษาดูนะครับ
ตัวอย่างเป็น การรับข้อมุลเฉพาะ post key ที่ตรงกับ field ที่ใช้งานเท่านั้น ไม่ได้รับตัวแปรส่วนขยาย

ปล. php ไม่แสดง error
เพิ่ม คำสั่งนี้ไว้ส่วนหัว
Code (PHP)
<?php
		error_reporting(-1);
		ini_set('display_errors', 1);




ประวัติการแก้ไข
2021-05-01 20:32:00
2021-05-01 20:37:13
2021-05-01 22:27:10
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 20:29:58 By : Chaidhanan
 


 

No. 29



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 27 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-01 20:29:55
รายละเอียดของการตอบ ::
ยังไม่ได้เลยครับ ไม่มี error ใด ๆ ออกมาครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 21:08:41 By : jgogo01
 


 

No. 30



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 28 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-05-01 20:29:58
รายละเอียดของการตอบ ::
ขอบคุณครับผม สำหรับคำแนะนำ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 21:21:54 By : jgogo01
 


 
Code (PHP)
if( isset($_POST["idcard_student"]) ){
    //...
    if (!$result_reg) { // ลองเปลี่ยนเงื่อนไขใหม่อาจมีผลกับ ===
        echo "error"; // เลือกเก็บไว้บรรทัดเดียว
        // die(mysqli_error($con));
    } else {
        echo "success";
    }
    exit;
}


ถ้าไม่ได้หดเหลือ

Code (PHP)
if( isset($_POST["idcard_student"]) ){
    //...

    echo "AJAX return";
    exit;
}


พยายามพลิกแพลงเฟ้นหา...เพราะมี syntax error หลัง query (เห็นบอกบันทึกเข้าฐานข้อมูลได้)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 22:02:21 By : พญามัจจุราช
 


 

No. 32



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 31 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-01 22:02:21
รายละเอียดของการตอบ ::
ยังไงก็ไม่ได้ครับ

งงมาก ผมไม่ค่อยได้ JS ซะด้วยครับ error ถ้ามีบอกหน่อยยังพอหาทางแก้ได้ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 22:17:14 By : jgogo01
 


 

No. 33



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


php เปิดให้แสดง error หรือยังครับ
ตัวอย่างทึ 2 คห.ที่ 28


ส่วนอันนี้เป็น ตัวอย่างการ ส่ง error code เพื่อนำไปประยุกต์ใช้ได้
Code (PHP)
if ( true )
   // ---- ส่งข้อความปกติ -----------
else   // กรณีผิดผลาด อาจส่ง เออเร่อร์ ตามต้องการได้
    header("HTTP/1.1 590 My Message error");




ประวัติการแก้ไข
2021-05-01 22:36:04
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 22:28:50 By : Chaidhanan
 


 

No. 34



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 33 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-05-01 22:28:50
รายละเอียดของการตอบ ::
เปิดแล้วครับผม ไม่มี error ใด ๆ ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 22:33:59 By : jgogo01
 


 
ลองเปลี่ยนจาก alert เป็น console.log ดูหรือยัง

Code (JavaScript)
success: res=>{console.log(res);}



response จะส่งกลับทั้ง data และ php error ติดมาด้วย (ถ้ามี syntax error)
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 22:57:30 By : พญามัจจุราช
 


 

No. 36



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 35 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-01 22:57:30
รายละเอียดของการตอบ ::
ได้ลองใส่แล้วครับ
ไม่มี error กลับมาที่ console.log ครับ



ประวัติการแก้ไข
2021-05-01 23:02:37
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-01 23:00:37 By : jgogo01
 


 

No. 37



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


ลองทำเป็นตัวอย่าง
ลองเล่นได้ที่ http://chaidhanan.thaigamehub.com/cert.php
Code (PHP)
<?php
error_reporting(-1);
ini_set('display_errors', 1);
//require('../../connect.php');
$con=new mysqli('localhost', 'test','test','test');
if(isset($_POST['submit']) ){
	$sql= ''; $ar=[];
	foreach($_POST['data'] as $k=>$val){
		$sql.=(strlen($sql)<1? 'INSERT INTO `student` set ' : ', ') . $k . '=?';
		$ar[]=$val;
	}
	//$stmt=$con->prepare($sql);
	//$stmt->bind_param(str_repeat('s',count($_POST), ...$_POST);
	//$stmt->execute();
	//if($stmt->errno>0) die( $stmt->error );
    echo json_encode(['data'=>$ar, 'sql'=>$sql, 'msg'=>'complete']);
    exit;
}
?><!doctype html>
<html>
<head>
<title>Test Ajax</title>
<link rel="stylesheet" href="/SQM/css/bootstrap.min.css" >
<link rel="stylesheet" href="/swal/sweetalert.css" >
<script src="/SQM/js/jquery-3.2.1.min.js" ></script>
<script src="/SQM/js/bootstrap.min.js" ></script>
<script src="/swal/sweetalert.min.js" ></script>
<script>
$(document).ready(()=>{
	$('button').click(()=>{
		if(!$('#confirm_true').prop('checked')){
			swal('ERROR', 'ท่านไม่ได้ยืนยันข้อมูล', 'error'); return;
		}
		var ar={};
		$('.for-post').each((i,o)=>{
			ar[o.name]=o.value;
		});
		$.ajax({url: '/cert.php', type: 'post', data:{submit:1,data: ar}, dataType: 'json',
			success:rs=>{
				swal('complete', JSON.stringify(rs.data)+"\r\n"+rs.sql,'success');
			},
			error: (jqXHR, exception)=>{
				var msg = '';
				if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.';
				} else if (jqXHR.status === 404) { msg = 'Requested page not found. [404]';
				} else if (jqXHR.status === 500) { msg = 'Internal Server Error [500].';
				} else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.';
				} else if (exception === 'timeout') { msg = 'Time out error.';
				} else if (exception === 'abort') { msg = 'Ajax request aborted.';
				} else { msg = 'Uncaught Error.\n' + jqXHR.responseText; }
				swal("error occured", msg, 'error'); //===Show Error Message====
			}
		});	
	});
});
</script>
</head>
<body>
<div class="container" >
	<form id="reg_form" >
 		<h2> <span class="badge badge-info">1.</span> <b>แผนการเรียน</b> </h2>
		<div class="row">
				<div class="form-group col-xl-6 col-xs-12">
					<label for="class_student">ระดับชั้น <text class="text-danger"> *</text> </label>
					<select class="form-control for-post" name="class_student" id="class_student" required>
					<option value="" disabled selected hidden>กรุณาเลือกระดับชั้น</option>
					<option value="1" >มัธยมศึกษาปีที่ 1</option>
					<option value="4" >มัธยมศึกษาปีที่ 4</option>
				</select>
				</div>

				<div class="form-group col-xl-6 col-xs-12">
					<label for="edutype_student">เขตพื้นที่ <text class="text-danger"> *</text> </label>
					<select class="form-control for-post" name="edutype_student" id="edutype_student" required>
					<option disabled selected hidden>กรุณาเลือกเขตพื้นที่</option>
					<option>ในเขตพื้นที่บริการ</option>
					<option>นอกเขตพื้นที่บริการ</option>
				</select>
				</div>
		</div>

		<div class="row">
			<div class="form-group col-xl-4 col-xs-12">
				<label for="eduplan_student">แผนการเรียน (อันดับ 1) <text class="text-danger"> *</text> </label>
				<select class="form-control for-post"  id="eduplan_student" name="eduplan_student"  required>
				<option value="" selected disabled> กรุณาเลือกแผนการเรียน </option>
				<option value="1" > แผนการเรียน 1 </option>
				<option value="2" > แผนการเรียน 2 </option>
				<option value="3" > แผนการเรียน 3 </option>
				</select>
			</div>	

			<div class="form-group col-xl-4 col-xs-12">
				<label for="eduplan2_student">แผนการเรียน (อันดับ 2) <text class="text-danger"> *</text> </label>
				<select class="form-control for-post"  id="eduplan2_student" name="eduplan2_student" required>
				<option value="" selected disabled> กรุณาเลือกแผนการเรียน </option>
				<option value="1" > แผนการเรียน 1 </option>
				<option value="2" > แผนการเรียน 2 </option>
				<option value="3" > แผนการเรียน 3 </option>
			</select>
			</div>

			<div class="form-group col-xl-4 col-xs-12">
				<label for="eduplan3_student">แผนการเรียน (อันดับ 3) <text class="text-danger"> *</text> </label>
				<select class="form-control for-post" id="eduplan3_student" name="eduplan3_student" required>
				<option value="" selected disabled> กรุณาเลือกแผนการเรียน </option>
				<option value="1" > แผนการเรียน 1 </option>
				<option value="2" > แผนการเรียน 2 </option>
				<option value="3" > แผนการเรียน 3 </option>
				</select>
			</div>
		</div>
		<hr>
 	
		<div class="text-center pt-3">
			<input type="checkbox" id="confirm_true" required> ข้าพเจ้าขอยืนยันว่าข้อมูลที่กรอกไป เป็นความจริงทุกประการ <br>
			<button type="button" class="btn btn-primary mt-3">ลงทะเบียน</button>
		</div>
	</form>
</div>
</body>
</html>



ประวัติการแก้ไข
2021-05-02 00:10:06
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-02 00:09:28 By : Chaidhanan
 


 

No. 38



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 37 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-05-02 00:09:28
รายละเอียดของการตอบ ::
ลิงก์เข้าไม่ได้ครับผม

จากที่ผมลองเอาโค้ดไปลง swal ออกมาแล้วครับ แต่ข้อมูลไม่ลง db แทน เดี๋ยวลองไล่สาเหตุดูครับ
swal ออกมาดังนี้ครับ
swal-sql



**เพิ่มเติม **
ได้ลองเอาโค้ดมาลง พร้อมสร้าง db ใหม่ ไม่ได้แก้ไขโค้ดใด ๆ ข้อมูลก็ไม่ลง db ครับ

- ลายละเอียด เว็บจำลอง Sever -
Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11
Database client version: libmysql - mysqlnd 7.4.11
PHP extension: mysqli Documentation curl Documentation mbstring Documentation
PHP version: 7.4.11

PHPMyAdmin
Version information: 5.0.3



ประวัติการแก้ไข
2021-05-02 15:36:46
2021-05-02 15:37:12
2021-05-02 15:42:15
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-02 13:10:39 By : jgogo01
 


 

No. 39



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 38 เขียนโดย : jgogo01 เมื่อวันที่ 2021-05-02 13:10:39
รายละเอียดของการตอบ ::
Powersupply เดี้่ยงพอดีครับ เลยเปิดเครื่องไม่ได้

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-02 18:44:14 By : Chaidhanan
 


 

No. 40



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 38 เขียนโดย : jgogo01 เมื่อวันที่ 2021-05-02 13:10:39
รายละเอียดของการตอบ ::
ถ้าไม่ได้แก้โค๊ดเลย ไม่ลงแน่นอนครับ เพราะ แค่ทดสอบ swal


ผมปิดการ insert ไว้ ปิด connection mysql ไว้ แค่ตัวอย่างการใช้ swal
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-02 18:46:49 By : Chaidhanan
 


 

No. 41



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 40 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-05-02 18:46:49
รายละเอียดของการตอบ ::
ขอบคุณครับผม ^^ นีกว่าผมผิดโค้ดตรงไหนอีก

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-02 19:12:26 By : jgogo01
 


 

No. 42



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 40 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-05-02 18:46:49
รายละเอียดของการตอบ ::
ถ้าจะเปิด insert ลง sql คือเอา tag comment ออกใช่ไหมครับ ผมไม่ค่อยเข้าใจเท่าไรครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-02 22:23:14 By : jgogo01
 


 

No. 43



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


จากพี่ 'Chaidhanan' แนะนำไว้ ใครใช้ JSON ลองทำดูนะครับ
ผมยังไม่ได้ลึกถึงขนาดนั้น

สำหรับใครที่ยังไม่ได้ ผมได้ใช้แค่ ajax ธรรมดาครับ
เผื่อใครยังไม่ได้ลองเอาโค้ดไปใช้นะครับ

แนะนำเพิ่มเติมได้นะครับผม ^^
Ajax_Send_Form.js
<!-- Ajax Send Data-->
<script>
$(document).ready(function(){
     $('#reg_form').on('submit', function(e){ // เช็ค submit ของ form
		e.preventDefault(); // เมื่อ ajax ไม่ให้ reload
		if(!$('#confirm_true').prop('checked')){ // เช็คว่ายอมรับข้อตกลงหรือยัง
			swal('กรุณายอมรับข้อตกลง!', 'ข้อมูลที่ท่านกรอกเป็นความจริงเท่านั้น', 'warning'); return;
		}
		else{
		var data_edu={}; // สร้างตัวแปร data_edu
		$('.for-post').each((i,o)=>{ // เก็บตัวแปร ที่มี class = "for-post"
			data_edu[o.name]=o.value;
		});

			$.ajax({url: 'sql/reg/insert_reg.php', type: 'POST', data: data_edu, // ส่งข้อมูลจากตัวแปร data_edu ด้วย ajax
			
		});

		// เมื่อกด Submit แล้วให้แสดง swal (ไม่ได้ตรวจ จาก ajax)
		swal("ลงทะเบียบสำเร็จ!", "กรุณาอัปโหลดเอกสารเพิ่มเติม", { 
											icon : "success",
											buttons: {        			
												confirm: {
													text: "ตกลง",
													className : 'btn btn-success'
												}
											},
										}).then(function(){ // เมื่อกด ตกลงใน swal ให้ window.location.reload(); เพื่อล้างค่าในฟอร์ม ป้องกันส่งซ้ำ
											window.location.reload();
										});
		}								
    });
});
</script>



inset_reg.php
<?php
require('../../connect.php');

// เช็คค่า idcard_s เข้ามาหรือยัง
if(isset($_POST['idcard_s']) ){

    // สร้างตัวแปร

    // 1.
    $class_s = mysqli_real_escape_string($con,$_POST['class_s']);
    $edutype_s = mysqli_real_escape_string($con,$_POST['edutype_s']);
    $eduplan_s = mysqli_real_escape_string($con,$_POST['eduplan_s']);
    $eduplan2_s = mysqli_real_escape_string($con,$_POST['eduplan2_s']);
    $eduplan3_s = mysqli_real_escape_string($con,$_POST['eduplan3_s']);

    //2.
    $idcard_s = mysqli_real_escape_string($con,$_POST['idcard_s']);
    $birthday_s = mysqli_real_escape_string($con,$_POST['birthday_s']);

    //3.
    $titlename_s = mysqli_real_escape_string($con,$_POST['titlename_s']);
    $fristname_s = mysqli_real_escape_string($con,$_POST['fristname_s']);
    $lastname_s = mysqli_real_escape_string($con,$_POST['lastname_s']);
    $race_s = mysqli_real_escape_string($con,$_POST['race_s']);
    $nationality_s = mysqli_real_escape_string($con,$_POST['nationality_s']);
	$religious_s = mysqli_real_escape_string($con,$_POST['religious_s']);
    $ban_number_s = mysqli_real_escape_string($con,$_POST['ban_number_s']);
    $moo_s = mysqli_real_escape_string($con,$_POST['moo_s']);
    $mooban_s = mysqli_real_escape_string($con,$_POST['mooban_s']);
    $sub_district_s = mysqli_real_escape_string($con,$_POST['sub_district_s']);
    $amphures_s = mysqli_real_escape_string($con,$_POST['amphures_s']);
    $province_s = mysqli_real_escape_string($con,$_POST['province_s']);
    $zip_code_s = mysqli_real_escape_string($con,$_POST['zip_code_s']);
    $h_tel_s = mysqli_real_escape_string($con,$_POST['h_tel_s']);
    $tel_s = mysqli_real_escape_string($con,$_POST['tel_s']);

    //4.
    $eduold_s = mysqli_real_escape_string($con,$_POST['eduold_s']);
    $school_s = mysqli_real_escape_string($con,$_POST['school_s']);
    $school_amphures_s= mysqli_real_escape_string($con,$_POST['school_amphures_s']);
    $school_province_s = mysqli_real_escape_string($con,$_POST['school_province_s']);
    $score_s = mysqli_real_escape_string($con,$_POST['score_s']);

    //5. 
    $titlename_f = mysqli_real_escape_string($con,$_POST['titlename_f']);
    $lastname_f = mysqli_real_escape_string($con,$_POST['lastname_f']);
    $fristname_f = mysqli_real_escape_string($con,$_POST['fristname_f']);
    $work_f = mysqli_real_escape_string($con,$_POST['work_f']);
    $location_work_f = mysqli_real_escape_string($con,$_POST['location_work_f']);
    $tel_f = mysqli_real_escape_string($con,$_POST['tel_f']);

    //6.
    $titlename_m = mysqli_real_escape_string($con,$_POST['titlename_m']);
    $fristname_m = mysqli_real_escape_string($con,$_POST['fristname_m']);
    $lastname_m = mysqli_real_escape_string($con,$_POST['lastname_m']);
    $work_m = mysqli_real_escape_string($con,$_POST['work_m']);
    $location_work_m = mysqli_real_escape_string($con,$_POST['location_work_m']);
    $tel_m = mysqli_real_escape_string($con,$_POST['tel_m']);

    //7.
    $titlename_p = mysqli_real_escape_string($con,$_POST['titlename_p']);
    $fristname_p = mysqli_real_escape_string($con,$_POST['fristname_p']);
    $lastname_p = mysqli_real_escape_string($con,$_POST['lastname_p']);
    $work_p = mysqli_real_escape_string($con,$_POST['work_p']);
    $loaction_work_p = mysqli_real_escape_string($con,$_POST['loaction_work_p']);
    $tel_p = mysqli_real_escape_string($con,$_POST['tel_p']);

    //8.
    $select_parent_s= mysqli_real_escape_string($con,$_POST['select_parent_s']);


    // ช่องเว้น '' คือ id table
    $query_reg= "INSERT INTO `student` VALUES('', '$class_s','$edutype_s','$eduplan_s','$eduplan2_s','$eduplan3_s' 
    ,'$idcard_s','$birthday_s'
    ,'$titlename_s','$fristname_s','$lastname_s','$race_s','$religious_s','$nationality_s','$ban_number_s','$moo_s','$mooban_s','$sub_district_s','$amphures_s','$province_s','$zip_code_s','$h_tel_s','$tel_s'
    ,'$eduold_s','$school_s','$school_amphures_s','$school_province_s','$score_s'
    ,'$titlename_f','$lastname_f','$fristname_f','$work_f','$location_work_f','$tel_f'
	,'$titlename_m','$fristname_m','$lastname_m','$work_m','$location_work_m','$tel_m'
    ,'$titlename_p','$fristname_p','$lastname_p','$work_p','$loaction_work_p','$tel_p'
    ,'$select_parent_s')";
    
    
    $result_reg = mysqli_query($con, $query_reg);

    if (false === $result_reg) {  
        echo "error";  
        die(mysqli_error($con));
    } 
    
    else {
        echo "success"; 
    }
}


?>



ประวัติการแก้ไข
2021-05-03 02:26:09
2021-05-08 19:27:53
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-02 23:52:54 By : jgogo01
 


 
จขกท. แก้ปัญหาได้แล้วใช่หรือไม่

ถ้ายัง ลองดูเรื่อง cache ด้วย
เพราะโค้ดไม่น่ามีปัญหาแล้ว
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-03 21:54:40 By : พญามัจจุราช
 


 

No. 45



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 44 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-03 21:54:40
รายละเอียดของการตอบ ::
ได้แต่วิธีธรรมดา ไม่ได้แสดงผลตอนส่ง ajax กลับ
ผมทำให้มันแสดงผลเลยตอนกดครับ ส่วน ajax ก็ทำงานไปครับ

ขอบคุณคำแนะนำครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-04 01:08:03 By : jgogo01
 


 

No. 46



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


เทคนิคที่ผมให้ไป โดยการใช้ mysqli::prepare เป็นการเขียนป้องกัน sql injection ที่สั้นที่สุด ไม่จำเป็นต้องใช้ mysqli_real_escape_string

เพราะมันจะแปลง ให้เอง

https://websitebeaver.com/prepared-statements-in-php-mysqli-to-prevent-sql-injection
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-04 07:14:27 By : Chaidhanan
 


 
ถ้าสังเกตเห็นว่า โปรแกรมไม่อัปเดตไม่ว่าจะแก้ alert เหลือแค่บรรทัดเดียว หรือใส่เพิ่มอีกแสนบรรทัด สงสัยได้ว่าอาจเป็นที่ cache
...ตอน dev ปิด browser cache แบบชั่วคราวไปก่อน (อย่าปิดถาวรด้วย script header) บางทีมันเต็ม

ตัวอย่างใน chrome : inspect(Ctrl+Shift+I) -> F1 (หน้า element) -> disable cache (...)

ปิด cache ใน chrome
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-04 11:10:33 By : พญามัจจุราช
 


 

No. 48



โพสกระทู้ ( 84 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 47 เขียนโดย : พญามัจจุราช เมื่อวันที่ 2021-05-04 11:10:33
รายละเอียดของการตอบ ::
ขอบคุณครับ สำหรับคำแนะนำ เพิ่มเติม


ตอบความคิดเห็นที่ : 46 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-05-04 07:14:27
รายละเอียดของการตอบ ::
ขอบคุณครับผม ^^

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-05-05 15:51:16 By : jgogo01
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อยากใช้ swal เมื่อ form action แล้ว ให้แสดง swal ทำอย่างไรครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่