Search code examples
phpmysqlsyntax-errorresource-id

Resource id #5 in mysql


<?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     |

Solution

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