Search code examples
mysql-error-1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 13


This is piece of my syntax if I don't write "or die (mysql_error())" then "Gagal" I don't know where is my fault. Please help ! thanks before

include "konekdb.php";

$query = mysql_query(
   "UPDATE proyek 
   SET nama_panj_proyek='$_POST[nama_panj_proyek]',
   nama_pend_proyek='$_POST[nama_pend_proyek]', 
   unit='$_POST[unit]', 
   tsk='$_POST[tsk]', 
   no_kontrak='$_POST[no_kontrak]', 
   tgl_kontrak='$_POST[tgl_kontrak]', 
   jenis_proyek='$_POST[jenis_proyek]', 
   no_sla='$_POST[no_sla]', 
   tanggal_sla='$tanggal_sla', 
   kode_akun='$_POST[kode_akun]', 
   pemberi_kerja='$_POST[pemberi_kerja]', 
   mulai_proyek='$mulai_proyek', 
   akhir_proyek='$akhir_proyek, 
   jangka_waktu='$jangka_waktu', 
   prog_overall='$_POST[prog_overall]', 
   prog_sipil='$_POST[prog_sipil]', 
   prog_mekanik='$_POST[prog_mekanik]', 
   prog_elektrik='$_POST[prog_elektrik]', 
   mm_sla='$_POST[mm_sla]', 
   mm_real='$_POST[mm_real]', 
   rbt_sla='$_POST[rbt_Sla]', 
   rbt_real='$_POST[rbt_real]', 
   bln_pro='$bln_pro', 
   thn_pro='$thn_pro', 
   ket='$_POST[ket]' 
   WHERE id_proyek='$_POST[id_proyek]'"
) or die (mysql_error());

   if($query){
      echo"Berhasil !";
      if($_POST['jenis_proyek']=='Pembangkit'){
         echo"<script>window.location='tampilproyekkit.php;'</script>";
      } else if($_POST['jenis_proyek']=='Jaringan'){
         echo"<script>window.location='tampilproyekjar.php;'</script>";
      }
   }else {
      echo"Gagal !";
   }
   exit;

And this is line 13

$tanggal_sla = $tgl_sla."-".$bln_sla."-".$thn_sla;
$tgl_mulai_proyek = $_POST['tgl_mulai_proyek'];

Solution

  • Line 13 of your SQL string, not your Code file :)

    akhir_proyek='$akhir_proyek,

    this is missing a closing quote should be:

    akhir_proyek='$akhir_proyek',

    You might also want to check up on SQL Injection, i may not be a PHP developer but the code above looks ripe for injection attack:

    Check this stack question for some help: How can I prevent SQL injection in PHP?