|
|
|
ช่วยดูให้หน่อยครับ ผมจะทำการ Update เพิ่มแล้วไม่ให้ค่าซ้ำในฐานข้อมูลอ่ะครับ |
|
|
|
|
|
|
|
ผมต้องการให้มันเช็คซ้ำเบอร์โทรศัพท์อะครับ tel1, tel2 โดยการที่เวลาอัพเดท tel2 เข้าไปแล้วไม่ให้ซ้ำกับเบอร์ในฐานข้อมูล
ผมใช้ f_ani1, f_ani2 แทนเบอร์โทรทั้ง2 นะครับ
ไม่ทราบว่าทำไมมันไม่เช็คซ้ำให้เลย แต่กลับ update ให้เฉย
Code (PHP)
<?
include "include/connect.php";
$birthday = $_POST['bYear']."-".$_POST['bMonth']."-".$_POST['bDate'];
$sql_cust = "select * from tbl_info_cust_det where f_cust_id = '$_POST[cust_id]'";
$result_sql_cust= mssql_query($sql_cust);
$row_cust=mssql_fetch_array($result_sql_cust);
$sql_list = "update tbl_info_contact_list SET f_firstname = '$_POST[c_name]', f_lastname = '$_POST[c_surname]' where f_firstname = '$row_cust[f_name]' and f_lastname = '$row_cust[f_surname]'";
mssql_query($sql_list);
//echo $sql_list;
$sql_main = "update tbl_info_contact_main SET f_firstname = '$_POST[c_name]', f_lastname = '$_POST[c_surname]' where f_firstname = '$row_cust[f_name]' and f_lastname = '$row_cust[f_surname]'";
mssql_query($sql_main);
//*** ตรวจสอบข้อมูลซ้ำ
$sql_tel="SELECT * FROM tbl_info_cust_det WHERE tel1='$f_ani1' OR tel2='$f_ani2'";
$query=mssql_query($sql_tel);
if(mssql_num_rows($query)>0)
{
echo "<script type='text/javascript'>alert('เบอร์โทรนี้มีอยู่แล้ว');window.history.go(-1);</script>" ;
exit();
}
// จบตรวจสอบข้อมูลซ้ำ
$sql = "update tbl_info_cust_det SET f_ani1 = '$_POST[tel1]', f_ani2 = '$_POST[tel2]', f_name = '$_POST[c_name]', f_surname = '$_POST[c_surname]', f_birthday = '$birthday', f_age = '$_POST[age]', f_sex = '$_POST[sex]', f_status = '$_POST[m_status]', f_weight = '$_POST[weight]', f_hight = '$_POST[hight]', f_occupation = '$_POST[job]', f_addr1_license = '$_POST[home_no1]', f_addr1_salutation = '$_POST[salutation_address1]', f_addr1_name = '$_POST[clientVillegeName1]', f_addr1_no = '$_POST[clientVillegeNo1]', f_addr1_soi = '$_POST[clientSoi1]', f_addr1_road = '$_POST[clientRoad1]', f_addr1_subdistrict = '$_POST[clientSubdistrict1]', f_addr1_district = '$_POST[clientDistrict1]', f_addr1_province = '$_POST[clientProvince1]', f_addr1_zipcode = '$_POST[clientZipcode1]', f_addr2_license = '$_POST[home_no2]', f_addr2_salutation = '$_POST[salutation_address2]', f_addr2_name = '$_POST[clientVillegeName2]', f_addr2_no = '$_POST[clientVillegeNo2]', f_addr2_soi = '$_POST[clientSoi2]', f_addr2_road = '$_POST[clientRoad2]', f_addr2_subdistrict = '$_POST[clientSubdistrict2]', f_addr2_district = '$_POST[clientDistrict2]', f_addr2_province = '$_POST[clientProvince2]', f_addr2_zipcode = '$_POST[clientZipcode2]' , f_cust_detail = '$_POST[cust_detail]', f_cust_remark = '$_POST[remark]' where f_cust_id = '$_POST[cust_id]'";
mssql_query($sql);
?>
<script type="text/javascript">
alert("บันทึกข้อมูลเรียบร้อย")
window.location = "edit_customer.php?cust_id=<? echo $_POST[cust_id];?>"
</script>
</body>
</html>
Tag : PHP, MySQL, Ms SQL Server 2008
|
ประวัติการแก้ไข 2014-10-09 08:45:37
|
|
|
|
|
Date :
2014-10-08 15:25:50 |
By :
lemonzaaa |
View :
867 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (PHP)
<?
include "include/connect.php";
$birthday = $_POST['bYear']."-".$_POST['bMonth']."-".$_POST['bDate'];
$sql_cust = "select * from tbl_info_cust_det where f_cust_id = '$_POST[cust_id]'";
$result_sql_cust= mssql_query($sql_cust);
$row_cust=mssql_fetch_array($result_sql_cust);
$sql_list = "update tbl_info_contact_list SET f_firstname = '$_POST[c_name]', f_lastname = '$_POST[c_surname]' where f_firstname = '$row_cust[f_name]' and f_lastname = '$row_cust[f_surname]'";
mssql_query($sql_list);
//echo $sql_list;
$sql_main = "update tbl_info_contact_main SET f_firstname = '$_POST[c_name]', f_lastname = '$_POST[c_surname]' where f_firstname = '$row_cust[f_name]' and f_lastname = '$row_cust[f_surname]'";
mssql_query($sql_main);
//*** ตรวจสอบข้อมูลซ้ำ
$sql_tel="SELECT * FROM tbl_info_cust_det WHERE tel1='$f_ani1' OR tel2='$f_ani2'";
$query=mssql_query($sql_tel);
if(mssql_num_rows($query)>0)
{
echo "<script type='text/javascript'>alert('เบอร์โทรนี้มีอยู่แล้ว');window.history.go(-1);</script>" ;
exit();
}else{
// จบตรวจสอบข้อมูลซ้ำ
$sql = "update tbl_info_cust_det SET f_ani1 = '$_POST[tel1]', f_ani2 = '$_POST[tel2]', f_name = '$_POST[c_name]', f_surname = '$_POST[c_surname]', f_birthday = '$birthday', f_age = '$_POST[age]', f_sex = '$_POST[sex]', f_status = '$_POST[m_status]', f_weight = '$_POST[weight]', f_hight = '$_POST[hight]', f_occupation = '$_POST[job]', f_addr1_license = '$_POST[home_no1]', f_addr1_salutation = '$_POST[salutation_address1]', f_addr1_name = '$_POST[clientVillegeName1]', f_addr1_no = '$_POST[clientVillegeNo1]', f_addr1_soi = '$_POST[clientSoi1]', f_addr1_road = '$_POST[clientRoad1]', f_addr1_subdistrict = '$_POST[clientSubdistrict1]', f_addr1_district = '$_POST[clientDistrict1]', f_addr1_province = '$_POST[clientProvince1]', f_addr1_zipcode = '$_POST[clientZipcode1]', f_addr2_license = '$_POST[home_no2]', f_addr2_salutation = '$_POST[salutation_address2]', f_addr2_name = '$_POST[clientVillegeName2]', f_addr2_no = '$_POST[clientVillegeNo2]', f_addr2_soi = '$_POST[clientSoi2]', f_addr2_road = '$_POST[clientRoad2]', f_addr2_subdistrict = '$_POST[clientSubdistrict2]', f_addr2_district = '$_POST[clientDistrict2]', f_addr2_province = '$_POST[clientProvince2]', f_addr2_zipcode = '$_POST[clientZipcode2]' , f_cust_detail = '$_POST[cust_detail]', f_cust_remark = '$_POST[remark]' where f_cust_id = '$_POST[cust_id]'";
mssql_query($sql);
}
?>
<script type="text/javascript">
alert("บันทึกข้อมูลเรียบร้อย")
window.location = "edit_customer.php?cust_id=<? echo $_POST[cust_id];?>"
</script>
</body>
</html>
ใช้ if(mssql_num_rows($query)>0) {
// No Update
// Direc กลับหน้า Form
}else{
// Update
}
|
|
|
|
|
Date :
2014-10-15 15:35:17 |
By :
bunchuai |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|