|
 |
|
ใครพอมีสคริปหรือโค๊ดตัวอย่าง เกี่ยวกับการใช้ชื่อซ้ำ และรหัสประจำตัวซ้ำบ้างคะ |
|
 |
|
|
 |
 |
|
แบบนี้อะป่าวคะ...
https://www.thaicreate.com/php/forum/035972.html
|
 |
 |
 |
 |
Date :
2012-04-02 14:50:32 |
By :
i_ann |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ประมาณนี้เลยคะ แต่โค๊ดมีแล้ว แต่จะเขียเพิ่มยังดีคะ
นี้โคํด
Code (PHP)
<?php
include('connect.php');
$cus_id = $_REQUEST['cus_id']; // คำสั่ง insert ข้อมูลผู้ใช้น้ำลงฐานข้อมูล
$cus_name = $_REQUEST['cus_name'];
$cus_lastname = $_REQUEST['cus_lastname'];
$cus_address = $_REQUEST['cus_address'];
$cus_phone = $_REQUEST['cus_phone'];
$miter_num = $_REQUEST['miter_num'];
$unit_begin = $_REQUEST['unit_begin'];
$cus_date = $_REQUEST['cus_date'];
$new_id_cus = mysql_result(mysql_query("Select Max(cus_id)+1 as MaxID from customer"),0,"MaxID");//เลือกเอาค่า id ที่มากที่สุดในฐานข้อมูลและบวก 1 เข้าไปด้วยเลย
if($new_id_cus==''){ // ถ้าได้เป็นค่าว่าง หรือ null ก็แสดงว่ายังไม่มีข้อมูลในฐานข้อมูล
$cus_id="00001";
}else{
$cus_id=sprintf("%05d",$new_id_cus);//ถ้าไม่ใช่ค่าว่าง
}
$sql1 = "INSERT INTO customer (cus_id,cus_name,cus_lastname,cus_address,cus_phone,miter_num,unit_begin,cus_date) values ('$cus_id','$cus_name','$cus_lastname','$cus_address','$cus_phone','$miter_num','$unit_begin','$cus_date') ";
$dbquery1 = mysql_db_query($dbname,$sql1);
if($dbquery1<>0)
{
$sql2 = "SELECT * FROM customer ORDER BY id DESC";
$dbquery2 = mysql_db_query($dbname,$sql2);
$rs = mysql_fetch_assoc($dbquery2);
$cus_id = $rs['cus_id'];
$unit_begin = $_REQUEST['unit_begin'];
$cus_date = $_REQUEST['cus_date'];
$sql3 = "INSERT INTO water_pay (cus_id,date_after,unit_after) VALUES ('$cus_id','$cus_date','$unit_begin')";
$dbquery3 = mysql_db_query($dbname,$sql3);
}
if($dbquery3<>0)
{
echo"
<script>
alert('บันทึกข้อมูลของ $cus_name เรียบร้อยแล้ว');
</script>
";
}else{
echo"
<script>
alert('ไม่สามารถบันทึกข้อมูลได้');
history.back(-1);
</script>
";
}
?>
|
 |
 |
 |
 |
Date :
2012-04-02 16:00:44 |
By :
-- |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แนะนำหน่อยคะ จากที่ให้โค๊ดมา แก้ตรงส่วนไหนคะ
|
 |
 |
 |
 |
Date :
2012-04-03 11:13:26 |
By :
// |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|