2013-10-09 104 views
0
<?php include "koneksi.php"; 
$kdj=$_POST['kdj']; 
$id=$_POST['id']; 
$qty = $_POST['qty']; 
$kodelagi = mysql_query("Select kd_jual from nota order by id_nota DESC LIMIT 1"); 

if((!empty($id)) && (!empty($kdj)) && (!empty($qty))) 
{ 
$query = mysql_query("INSERT INTO nota (id_item,qty,kd_jual) 
values ('$id','$qty','$kodelagi');"); 
?><script language="Javascript">; 
document.location = 'transaksi.php' </script><?php 
}else 
{ 
print "<script>alert('Maaf, tidak boleh ada field yang kosong !'); 
javascript:history.go(-1);</script>"; 
}?> 

知道爲什麼這不起作用?我只想拿最後一個記錄從表上我的數據庫進行插入另一條記錄。它的工作,但是當我看到DB 的kd_jual由「資源ID#5」填補,不是我想要的..請幫助mysql中的資源ID#5

我的表 「諾塔」:

______________________________________________ 
|id_nota | id_item | qty | kd_jual   | 
|1  | 381  | 3 | 09-10-201303:45:46 | 
|2  | 11  | 5 | Resource id #5  | 
+1

你應該讀與'和mysql_fetch_row($查詢)'數據庫信息來獲取結果。我強烈建議切換到'mysqli'或'pdo'。 –

+0

將'$ _POST'數據直接放入查詢中? [什麼可能會出錯?](http://bobby-tables.com/) – tadman

回答

0

添加一行在評論

<?php include "koneksi.php"; 
    $kdj=$_POST['kdj']; 
    $id=$_POST['id']; 
    $qty = $_POST['qty']; 
    $kodelagi = mysql_query("Select kd_jual from nota order by id_nota DESC LIMIT 1"); 
    ////////////////// add these two lines to fetch the results 
    $row = mysql_fetch_array($kodelagi); 
    $kodelagi1 = $row['kd_jual']; 
    ////////////////// 
    if((!empty($id)) && (!empty($kdj)) && (!empty($qty))) 
    { 
    $query = mysql_query("INSERT INTO nota (id_item,qty,kd_jual) 
    values ('$id','$qty','$kodelagi1');"); ////// $kodelagi1 fetched value 
    ?><script language="Javascript">; 
    document.location = 'transaksi.php' </script><?php 
    }else 
    { 
    print "<script>alert('Maaf, tidak boleh ada field yang kosong !'); 
    javascript:history.go(-1);</script>"; 
    }?>