|
 |
|
มันฟ้องว่าซ้ำตลอดเลยคับ ทั้งที่ซ้ำจิงไม่และไม่จิง ผมลองหาวิธีเขียนตามกระทู้ที่พี่ๆเคยลงไว้ |
|
 |
|
|
 |
 |
|
ผมลองหาวิธีเขียนตามกระทู้ที่พี่ๆเคยลงไว้ ทำตามหลายแบบแล้วแต่ก็มันยังฟ้องว่า ซ้ำ ตลอดเลยครับ อันนี้ผมให้ id เป็น auto increment คับ รหัสไม่ซ้ำแน่ แต่ว่าอยากจะเช็คค่ารหัสย่อของลูกค้า ว่าซ้ำกันรึป่าว รบกวนพี่ๆช่วยดูให้หน่อยเถอะคับ
Code (PHP)
<?php
function isInsert(){
$Sql = "SELECT * FROM customer WHERE CustCode ='$CustCode' "; //ตรวจสอบรหัสย่อของลูกค้าว่าซ้ำมั๊ย เพราะว่าตัว ID ของลูกค้ามัน เป็น auto อยู่แล้วคับ
$query = mysql_query($Sql);
$objResult = mysql_fetch_array($query);
if($objResult)
{
echo"<script>alert('ซ้ำ');history.back();</script>";
}else{
$StrSql = "INSERT INTO customer(CustomerID, CustCode, CustID, CompanyName_EN, CompanyName_TH, ContactAddress, CustPhone, CustFax, CustEMail, ContactPerson1, ContactPerson2, CustDepartment, CustDiscoveRate, BTypeID, CTypeID,TermOfPayment,date_connect,cust_source, EmpID, event ,CustQuoNo)
VALUES('CustomerID', 'CustCode', 'CustID', 'CompanyName_EN', 'CompanyName_TH', 'ContactAddress', 'CustPhone', 'CustFax', 'CustEMail', 'ContactPerson1', '$this->ContactPerson2', 'CustDepartment', 'CustDiscoveRate', 'BTypeID', 'CTypeID','TermOfPayment','date_connect','cust_source', 'EmpID', 'event', 'CustQuoNo')";
mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
echo "เพิ่มข้อมูลเรียบร้อย";
}
}
?>
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2009-07-08 09:56:21 |
By :
maruk |
View :
920 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่น้องครับใช้ mysql_numrows แทน mysql_fetch_array นะครับ ให้เช็คว่ามันมากกว่า 0 หรือไม่
|
 |
 |
 |
 |
Date :
2009-07-08 10:00:47 |
By :
gon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$sql = "SELECT name From tbl_member WHERE CustCode ='$CustCode' " ;
$result = mysql_query( $sql);
if (mysql_fetch_array($result)) {
echo"<script>alert('ซ้ำ!');window.location='javascript:history.back()';</script>";
exit();
} else {
เพิ่มลง db
}
ส่วนตอนเพิ่ม ผมไม่แน่ใจว่า $this->ContactPerson2 มันคืออะไรอ่ะครับ คำสั่งเชคค่าซ้ำน่าจะไม่ผิด แต่อาจผิดตรงนี้ก็ได้ ยังไง ลอง echo ค่ามันออกมาดูนะครับ
deawx
[email protected]
ปรึกษา PHP ฟรีจ้า
|
 |
 |
 |
 |
Date :
2009-07-08 13:06:16 |
By :
deawx |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ ทั้งคุณ deawx และคุณ Guest มากคับ ผมทำได้แล้วคับ
ส่วนตัว $this->ContactPerson2 นั้นที่จิงรูปแบบเต็มๆของโค๊ดมันเป็นแบบนี้คับ
(ผมใช้ class )
Code (PHP)
<?php
function isInsert(){
$Sql = "SELECT * FROM `customer` WHERE `CustCode` ='".$this->CustCode."' ";
$query = mysql_query($Sql);
$objResult = mysql_num_rows($query);
if($objResult==0)
{
$StrSql = "INSERT INTO `customer`(`CustomerID`, `CustCode`, `CustID`, `CompanyName_EN`, `CompanyName_TH`, `ContactAddress`, `CustPhone`, `CustFax`, `CustEMail`, `ContactPerson1`, `ContactPerson2`, `CustDepartment`, `CustDiscoveRate`, `BTypeID`, `CTypeID`,`TermOfPayment`,`date_connect`,`cust_source`, `EmpID`, `event` ,`CustQuoNo`) VALUES('$this->CustomerID', '$this->CustCode', '$this->CustID', '$this->CompanyName_EN', '$this->CompanyName_TH', '$this->ContactAddress', '$this->CustPhone', '$this->CustFax', '$this->CustEMail', '$this->ContactPerson1', '$this->ContactPerson2', '$this->CustDepartment', '$this->CustDiscoveRate', '$this->BTypeID', '$this->CTypeID','$this->TermOfPayment','$this->date_connect','$this->cust_source', '$this->EmpID', '$this->event', '$this->CustQuoNo')";
$this->Conn->exeInsertQuery($StrSql);
//echo"$StrSql;";
}else{
echo"<script>alert('Code ลูกค้าซ้ำค่ะ ');window.location='javascript:history.back()';</script>";
exit;
}
?>
|
 |
 |
 |
 |
Date :
2009-07-08 14:43:19 |
By :
maruk |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|