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>";
}?> 

know why this doesn't work? I just want take last record from a table on my DB for insert another record.. its work but when I saw DB the kd_jual is filled by "Resource id #5" , not what I want.. please help

My table "nota":

______________________________________________
|id_nota | id_item | qty | kd_jual            |
|1       | 381     | 3   | 09-10-201303:45:46 |
|2       | 11      | 5   | Resource id #5     |
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
DaneSuegi
  • 7
  • 4
  • 1
    You should read database information with `mysql_fetch_row($query)`. I would highly recommend switching over to `mysqli` or `pdo`. – Dave Chen Oct 09 '13 at 03:27
  • Putting `$_POST` data directly in the query? [What could possibly go wrong?](http://bobby-tables.com/) – tadman Oct 09 '13 at 04:28

1 Answers1

0

add the line to fetch results in comments

<?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>";
    }?> 
user2092317
  • 3,226
  • 5
  • 24
  • 35