-1

Parse error: syntax error, unexpected ''.$_POST['' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\jawara\fct\proses_penjualan.php on line 6

<?php
if (isset($_POST['add'])) {
  $kode_produk=$_POST['kode_produk'];
  $jumlah=$_POST['jumlah'];
  $no_nota=$_POST['no_nota'];
  $pembanding=mysql_query ("select stok from produk where kode_produk="'.$_POST['kode_produk'].'"");
  if (mysql_num_rows($pembanding)<$_POST['jumlah']){
      $query=mysql_query("insert into transaksi_keluar_temp values ('','$no_nota','$kode_produk','$jumlah')");
      if($query)
      {
        echo "<script type='text/javascript'> onload =function(){ alert('Data Berhasil Ditambahkan');}</script>";
      }
      else
      {
        echo "<script type='text/javascript'> onload =function(){ alert('Stok Kurang Dari $pembanding');}</script>";
      }
  }
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
heri s
  • 9
  • 2
  • Use it as `produk where kode_produk='".$_POST['kode_produk']."'` and `mysql` is deprecated instead use `mysqli or PDO` – Saty Feb 02 '16 at 11:21
  • 2
    `='"` not `="'`, and `"'"` after rather than `'""`..... but you should be using MySQLi or PDO rather than MySQL in 2016, and prepared statements/bind variables rather than SQL injection holes that you've created.... welcome to the 21st century – Mark Baker Feb 02 '16 at 11:21
  • `$pembanding=mysql_query ("select stok from produk where kode_produk='".$kode_produk."'");` try this – Alive to die - Anant Feb 02 '16 at 11:22
  • @heri s its your responsibility to check the answers and mark them. This is the way how stack overflow work. you mark answer will help others. Thanks – Alive to die - Anant Feb 02 '16 at 11:40
  • thanks for the answer, I want to limit the amount of purchases that do not pass the amount of stock, how do I do it? – heri s Feb 02 '16 at 11:43
  • @heris i a the first person who gave you the answer, but you marked another one. – Alive to die - Anant Feb 02 '16 at 17:40

3 Answers3

0

Check your sql query -

Try this -

$pembanding=mysql_query (select stok from produk where kode_produk='".$_POST['kode_produk']."');
Rahul
  • 763
  • 1
  • 12
  • 45
0

Change

$pembanding=mysql_query ("select stok from produk where kode_produk="'.$_POST['kode_produk'].'"");

To

$pembanding=mysql_query ("select stok from produk where kode_produk='$kode_produk'");

[NOTE : mysql_* is deprecated. Use mysqli_* or PDO]

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
0

Replace Your Query (In your Query concatenation problem

 $pembanding=mysql_query ("select stok from produk where kode_produk="'.$_POST['kode_produk'].'"");

with

$pembanding=mysql_query ("select stok from produk where kode_produk="'".$_POST['kode_produk']."'");

always try in your best practice do not use $_POST in your query directly

Ajeet Kumar
  • 805
  • 1
  • 7
  • 26