<?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"填充,而不是我想要的。请帮忙
我的表"nota":
______________________________________________
|id_nota | id_item | qty | kd_jual |
|1 | 381 | 3 | 09-10-201303:45:46 |
|2 | 11 | 5 | Resource id #5 |
添加行以在注释中获取结果
<?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>";
}?>