[eluser]Mario "St.Peter" Valentino[/eluser]
Code:
public function pembelian_save($katalog_id,$nama,$email,$telepon,$handphone,$alamat,$pesan)
{
$this->db->trans_begin();
$user_id = date("Ymd").'-';
$max_user = $this->check_max_user($user_id);
if($max_user=='')
{
$urutan = 1;
$user_id .= $urutan;
}
else
{
$urutan = $max_user+1;
$user_id .= $urutan;
}
if($this->db->query("INSERT INTO tbl_client(id_client,
nama,
email,
telp,
handphone,
alamat,
remark,
urutan)
VALUES ('".$user_id."',
'".$nama."',
'".$email."',
'".$telepon."',
'".$handphone."',
'".$alamat."',
'".$pesan."',
'".$urutan."')"))
{
$order_id = $katalog_id.'-'.date("Ymd").'-';
$max_order = $this->check_max_order($order_id);
if($max_order=='')
{
$urutan_order = 1;
$order_id .= $urutan_order;
}
else
{
$urutan_order = $max_order+1;
$order_id .= $urutan_order;
}
if($this->db->query("INSERT INTO tbl_order (id_order,
id_client,
id_katalog,
tgl_order,
status,
urutan)
VALUES ('".$order_id."',
'".$user_id."',
'".$katalog_id."',
'".date("Y-m-d h:m:s")."',
'0',
'".$urutan_order."')"))
{
$no = 1;
foreach($this->cart->contents() as $items)
{
$id_produk = $items['id'];
$qty = $items['qty'];
$price = $items['price'];
if($this->db->query("INSERT INTO tbl_cart (id_order,id_produk,qty,harga,urutan)
VALUES ('".$order_id."',
'".$id_produk."',
'".$qty."',
'".$price."',
'".$no."')"))
{
$this->db->query("UPDATE tbl_produk SET produk_stok = produk_stok-".$qty." WHERE produk_id='".$id."'");
}
$no++;
}
}
}
//$this->db->trans_complete();
if($this->db->trans_status()===FALSE)
{
$this->db->trans_rollback();
//return false;
}
else
{
$this->db->trans_commit();
//return true;
}
}
i try this but when syntax error it still saving not rollback.
please give solution
the error syntax is in $id is not exists