|
 |
|
Error Save []...............UPDATE ข้อมูลเเล้วมันไม่ได้ |
|
 |
|
|
 |
 |
|
เอา Code มาดูหน่อยครับ 
|
 |
 |
 |
 |
Date :
2013-04-23 12:33:42 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
UPDATE bill SET bill_number = '100002' ,date_receive = '2013-04-19' ,receive_name = 'นางสาวกนกวรรณ เช้าฉ้อง' WHERE bill_number = ' 100002'
SET bill_number = '100002'
WHERE bill_number = ' 100002'
bill_number ตรง Where มีช่องว่างอยู่ข้างหน้า
อีกอย่าง bill_number นี่เป็น PK หรือเปล่าครับ ไม่เห็นต้อง SET value มันใหม่
|
 |
 |
 |
 |
Date :
2013-04-23 12:52:57 |
By :
WiTT |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เป็นไฟล์ save_store
ตอนนี้ insert ข้อมูลลงตาราง bill ยังไม่ได้
<? include "connect.php"; ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<? $receive_name = $_POST['receive_name'];
$brach_no = $_POST["branch"];
$color = $_POST["color"];
$province = $_POST["province"];
$regis_year = $_POST["regis_year"];
$selbrand = $_POST["selbrand"];
$selClass = $_POST["selClass"];
$selType = $_POST["selType"];
/*แปลงวันที่ลง DB*/
$date_receive = $_POST['date_receive'];
$date_y = substr($date_receive,6,6);
$date_y = $date_y-543;
$date_y;
$date_m = substr($date_receive,3,2);
$date_d = substr($date_receive,0,2);
$save_fulldate = $date_y."-".$date_m."-".$date_d;
$strSQL1 = "INSERT INTO stock_receive_motor (branch_no,bill_number,machine_id,chassis_id,brand,class,type,color,plate,province,regis_year,status_motor,buy,sell,status_stock)
VALUES ('$branch_no','".$_POST["bill_number"]."','".$_POST["machine_id"]."','".$_POST["chassis_id"]."','$selbrand','$selClass','$selType','$color','".$_POST["plate"]."','$province','$regis_year','".$_POST["status_motor"]."','".$_POST["buy"]."','".$_POST["sell"]."','1')";
$objQuery1 = mysql_query($strSQL1) or die(mysql_error());
//query ตาราง bill มาว่าจะ update หรือ insert
$strSQL3 = "SELECT * FROM bill ";
$objQuery3 = mysql_query($strSQL3);
$objResult3 = mysql_fetch_array($objQuery3);
$n=mysql_num_rows($objQuery3);
while($objResult3 = mysql_fetch_array($objQuery3))
{
$bill_number = $objResult3["bill_number"];
}
echo $bill_number;
echo "<br>";
echo $_POST["bill_number"];
echo "<br>";
if($_POST['bill_number'] == $bill_number)
{
//echo 'update';
$strSQL4 = "UPDATE bill SET ";
$strSQL4 .="bill_number = '".$_POST["bill_number"]."' ";
$strSQL4 .=",date_receive = '$save_fulldate' ";
$strSQL4 .=",receive_name = '$receive_name' ";
$strSQL4 .="WHERE bill_number = '$bill_number' ";
$objQuery4 = mysql_query($strSQL4) or die(mysql_error());
//echo $strSQL4;
}else
{
$strSQL5 = "INSERT INTO bill (bill_number,date_receive,receive_name)
VALUES ('".$_POST["bill_number"]."','$save_fulldate','$receive_name')";
$objQuery5 = mysql_query($strSQL5) or die(mysql_error());
//echo $strSQL;
}
$strSQL = "INSERT INTO stock_estimate (bill_number,machine_id,chassis_id,brand,class,type,color,plate,province,regis_year,status_motor,buy,sell,status_stock)
VALUES ('".$_POST["bill_number"]."','".$_POST["machine_id"]."','".$_POST["chassis_id"]."','$selbrand','$selClass','$selType','$color','".$_POST["plate"]."','$province','$regis_year','".$_POST["status_motor"]."','".$_POST["buy"]."','".$_POST["sell"]."','1')";
$objQuery = mysql_query($strSQL) or die(mysql_error());
if($objQuery)
{
echo "<script>alert('บันทึกเรียบร้อยแล้ว');</script>";
echo"<meta http-equiv='refresh' content='1;URL=add_store.php?bill_number=$bill_number'>";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close();
?>
|
 |
 |
 |
 |
Date :
2013-04-23 13:22:41 |
By :
lookpla26 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
บรรทัดที่ 37 :หลังจากที่รับค่ามาเปรียบเทียบกันแล้ว มันจะลง UPDATE ตลอด กรณีของ else มันก้อจะ UPDATE ด้วย
|
 |
 |
 |
 |
Date :
2013-04-23 13:59:25 |
By :
lookpla26 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
ประวัติการแก้ไข 2013-04-23 14:47:07
 |
 |
 |
 |
Date :
2013-04-23 14:21:22 |
By :
lookpla26 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ข้อมูลเข้า UPDATE ตลอดเลยอ้ะค้ะ แก้ไม่ถูกแล้ว
<? include "connect.php"; ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?
$bill_id = $_POST['$bill_id'];
$receive_name = $_POST['receive_name'];
$branch_no = $_POST["branch"];
$color = $_POST["color"];
$province = $_POST["province"];
$regis_year = $_POST["regis_year"];
$selbrand = $_POST["selbrand"];
$selClass = $_POST["selClass"];
$selType = $_POST["selType"];
/*แปลงวันที่ลง DB*/
$date_receive = $_POST['date_receive'];
$date_y = substr($date_receive,6,6);
$date_y = $date_y-543;
$date_y;
$date_m = substr($date_receive,3,2);
$date_d = substr($date_receive,0,2);
$save_fulldate = $date_y."-".$date_m."-".$date_d;
$strSQL1 = "INSERT INTO stock_receive_motor (branch_no,bill_number,machine_id,chassis_id,brand,class,type,color,plate,province,regis_year,status_motor,buy,sell,status_stock)
VALUES ('$branch_no','".$_POST["bill_number"]."','".$_POST["machine_id"]."','".$_POST["chassis_id"]."','$selbrand','$selClass','$selType','$color','".$_POST["plate"]."','$province','$regis_year','".$_POST["status_motor"]."','".$_POST["buy"]."','".$_POST["sell"]."','1')";
$objQuery1 = mysql_query($strSQL1) or die(mysql_error());
//query ตาราง bill มาว่าจะ update หรือ insert
$strSQL3 = "SELECT * FROM bill ";
$objQuery3 = mysql_query($strSQL3);
$objResult3 = mysql_fetch_array($objQuery3);
$n=mysql_num_rows($objQuery3);
while($objResult3 = mysql_fetch_array($objQuery3))
{
$bill_number = $objResult3["bill_number"];
}
/*echo $bill_number;
echo "<br>";
echo $_POST["bill_number"];
echo "<br>";*/
if($_POST['bill_number'] == $bill_number)
{
echo 'update';
$strSQL4 = "UPDATE bill SET ";
$strSQL4 .="bill_number = '".$_POST["bill_number"]."' ";
$strSQL4 .=",date_receive = '".$save_fulldate."' ";
$strSQL4 .=",receive_name = '".$receive_name."' ";
$objQuery4 = mysql_query($strSQL4) or die(mysql_error());
//echo $strSQL4;
}else
{
echo 'insert';
$strSQL4 = "INSERT INTO bill (bill_number,date_receive,receive_name)
VALUES ('".$_POST["bill_number"]."','$save_fulldate','$receive_name')";
$objQuery4 = mysql_query($strSQL4) or die(mysql_error());
//echo $strSQL4;
}
$strSQL = "INSERT INTO stock_estimate (bill_number,machine_id,chassis_id,brand,class,type,color,plate,province,regis_year,status_motor,buy,sell,status_stock)
VALUES ('".$_POST["bill_number"]."','".$_POST["machine_id"]."','".$_POST["chassis_id"]."','$selbrand','$selClass','$selType','$color','".$_POST["plate"]."','$province','$regis_year','".$_POST["status_motor"]."','".$_POST["buy"]."','".$_POST["sell"]."','1')";
$objQuery = mysql_query($strSQL) or die(mysql_error());
if($objQuery)
{
echo "<script>alert('บันทึกเรียบร้อยแล้ว');</script>";
echo"<meta http-equiv='refresh' content='1;URL=add_store.php?bill_number=$bill_number'>";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close();
?>
|
 |
 |
 |
 |
Date :
2013-04-23 15:02:54 |
By :
lookpla26 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$_POST['bill_number'] == $bill_number
คุณใช้เงื่อนไขตอน if ผิด ค่า 2 ตัวนี้มันเท่ากันตลอด มันก็เลย update ตลอด
|
 |
 |
 |
 |
Date :
2013-04-23 15:48:27 |
By :
pklngkua |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนชื่อของ $_POST['bill_number'] เป็นอบ่างอื่นดู ว่าได้้หรือเปล่า
ผมเข้าใจว่า มันหน้าจะไปเก็บอยู่ในตัวแปลเดียวกัน
|
 |
 |
 |
 |
Date :
2013-04-23 15:58:34 |
By :
pklngkua |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 11 เขียนโดย : lookpla26 เมื่อวันที่ 2013-04-23 16:14:33
<td align="right" width="15%">เลขที่ใบรับสินค้า :</td>
<td width="21%" align="left">
<?
//echo $_GET["bill_number"];
if($bill_number == $_GET["bill_number"]){ ?>
<input type="text" name="bill_number" id="bill_number" value="<?=$_GET["bill_number"]; ?>" class="tbl_box2" size="25"/>
<input type="hidden" name="bill_id" value="<?=$_GET["bill_number"]; ?>"">
<?
}else
{ ?>
<input type="text" name="bill_number" id="bill_number" class="tbl_box2" size="25"/>
<?
}
?>
</td>
ส่วนของฟอร์มที่กรอกเลขรับสินค้า
|
ประวัติการแก้ไข 2013-04-23 16:15:51 2013-04-23 16:16:12
 |
 |
 |
 |
Date :
2013-04-23 16:15:37 |
By :
lookpla26 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยนชื่อ input ใหม่ไปเลย จาก bill_number ก็เป็น bill_number2,bill_number3
พยายามอย่าให้ซ้ำกัน มันจะได้ตามแก้ไขได้ง่าย
|
 |
 |
 |
 |
Date :
2013-04-23 16:20:37 |
By :
pklangkua |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|