พอดีอยากให้มันเช็คค่าซ้ำก่อน เพิ่มข้อมูล ลงฐานข้อมูลอะครับ #มือใหม่หัดขับ
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา พอดีอยากให้มันเช็คค่าซ้ำก่อน เพิ่มข้อมูล ลงฐานข้อมูลอะครับ #มือใหม่หัดขับ
พอดีอยากให้มันเช็คค่าซ้ำก่อน เพิ่มข้อมูล ลงฐานข้อมูลอะครับ #มือใหม่หัดขับ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | ที่เป็นตอนนี้คือข้อมูลซ้ำก็ไม่มีการแจ้งเตือนใดๆครับแต่ก็จะไม่ไปเพิ่มลงในฐานข้อมูลเช่นกัน แต่หากตรงตามเงื่อนไขก็เพิ่มลงฐานข้อมูลปกติครับแต่มันไม่รีเฟรชหน้าให้ใหม่แล้วก็ไม่ซ่อนโมเดลด้วยครับ < div class = "modal fade" id = "teacheradd2" tabindex = "-1" role = "dialog" aria-labelledby = "myModalLabel" > < div class = "modal-dialog modal-sm" role = "document" > < div class = "modal-content" > < div class = "modal-header" > < button type = "button" class = "close" data-dismiss = "modal" aria-label = "Close" >< span aria-hidden = "true" >×</ span ></ button > < h4 class = "modal-title" id = "myModalLabel" >เข้าสู่ระบบ</ h4 > </ div > < form data-toggle = "validator" role = "form" id = "teacher-add" method = "POST" > < div class = "modal-body" > < div class = "form-group" > < label for = "Username" >ชื่อ - นามสกุล</ label > < input type = "text" id = "name" name = "name" placeholder = "ชื่อ-นามสกุล" class = "form-control" required> < span class = 'glyphicon form-control-feedback' aria-hidden = 'true' ></ span > </ div > < div class = "form-group" > < label for = "Password" >E-Mail</ label > < input type = "email" id = "email" name = "email" placeholder = "E-Mail" class = "form-control" required> < span class = 'glyphicon form-control-feedback' aria-hidden = 'true' ></ span > </ div > < div class = "form-group" > < label for = "first_name" >Password</ label > < input type = "text" id = "pw" name = "pw" placeholder = "Password" class = "form-control" required> </ div > < div class = "form-group" > < label >ประเภทผู้ใช้งาน</ label > < select class = "form-control" id = "type" name = "type" required> < option value = "1" >เจ้าหน้าที่</ option > < option value = "2" >อาจารย์</ option > </ select > </ div > < div class = "form-group" > < label >เปิด/ปิด สถานะการใช้งาน</ label > < select class = "form-control" id = "enable" name = "enable" required> < option value = "1" >เปิด</ option > < option value = "2" >ปิด</ option > </ select > </ div > </ div > < div class = "modal-footer" > < button type = "button" class = "btn btn-default" data-dismiss = "modal" >ปิด</ button > < button type = "submit" class = "btn btn-primary" > บันทึก</ button > </ div > </ form > </ div > </ div > </ div > |
1 | < script > |
$(document).ready(function(){
$('#teacher-add').on('submit',function(e){
e.preventDefault();
$.ajax({
url:"controller/teacher/addteacher.php",
method:"post",
data:$('#teacher-add').serialize(),
successs:function(data,textStatus){
if (data == '1name') {
$('.form-group:nth-child(2)').addClass('has-success has-feedback');
$('.form-group:nth-child(2)').removeClass('has-error');
$('.form-group:nth-child(2) > span').addClass('glyphicon-ok');
$('.form-group:nth-child(2) > span').removeClass('glyphicon-remove');
}else{
if (data == '1email') {
alert('กรุณาใส่เนื้อหาโครงงาน');
}else{
$('#teacher-add')[0].reset();
$('#teacheradd2').modal('hide');
location.reload();
}
}
}
});
});
});
</script>
<?php
include("db_con.php");
$name = $_POST['name'];
$email = $_POST['email'];
$pw = $_POST['pw'];
$type = $_POST['type'];
$enable = $_POST['enable'];
$sqlteacher = mysql_query("select * from teacher where t_name ='$name'");
$numteacher = mysql_num_rows($sqlteacher);
if ($numteacher == 1) {
echo "1name";
}else{
$sqlteacheremail = mysql_query("select * from teacher where t_email ='$email'");
$numteacheremail = mysql_num_rows($sqlteacheremail);
if ($numteacheremail == 1) {
echo "1email";
}else{
$query = "INSERT INTO teacher(t_name, t_email, t_pw, t_type, t_en) VALUES('$name', '$email', '$pw', '$type', '$enable')";
if ($result = mysql_query($query)) {
echo "add";
}else{
echo "error";
}
}
}
?>

คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
ความคิดเห็นที่
1

ขอบคุณทุกการสนับสนุน
![]()