After searching for problems identical to mine and found no solution I decided to ask here.
I have 2 tables in 1 db, one is "produk" the other is "sparepart" both have the exact same number and name of columns.
I wrote the exact same code of HTML and PHP, just changed the table name so the data will be stored to their respective table.
the problem is the data from produk.php is stored in produk table but, the data from sparepart.php is not stored in sparepart table after query.
I tried checking for errors, but no error generated and instead it echoes "success".
please take a look at my simplified code :
HTML
<?php echo "<header><h3>TAMBAHKAN PRODUK SPAREPART</h3></header>
<form method=POST action='$aksi?module=sparepart&act=input' enctype='multipart/form-data'>
<div class='module_content'>
<table id='rounded-corner'>
<tr>
<td width=70>Nama Produk</td>
<td> : <input type=text name='nama_produk' size=60></td>
</tr>
<tr>
<td>Kategori</td>
<td> :
<select name='kategori'>
<option value=0 selected>- Pilih Kategori -</option>";
$tampil=mysql_query("SELECT * FROM kategori ORDER BY nama_kategori");
while($r=mysql_fetch_array($tampil)){
echo "<option value=$r[id_kategori]>$r[nama_kategori]</option>";
}
echo "</select>
</td>
</tr>
<tr>
<td>Kategori 2</td>
<td> :
<select name='kategori2'>
<option value=0 selected>- Pilih Kategori2 -</option>";
$tampil2=mysql_query("SELECT * FROM kategori2 ORDER BY nama_kategori2");
while($r2=mysql_fetch_array($tampil2)){
echo "<option value=$r2[id_kategori2]>$r2[nama_kategori2]</option>";
}
echo "</select>
</td>
</tr>
<tr>
<td>Harga </td>
<td> : <input type=text name='harga' size=10></td>
</tr>
<tr>
<td>Stok</td>
<td> : <input type=text name='stok' size=5></td>
</tr>
<tr>
<td>Diskon</td>
<td> : <input type=text name='diskon' size=5></td>
</tr>
<tr>
<td>Potongan</td>
<td> : <input type=tetxt name='potongan' size=10></td>
</tr>
<tr>
<td valign=top>Deskripsi</td>
<td> <textarea name='deskripsi' style='width: 600px; height: 350px;'></textarea></td>
</tr>
<tr>
<td>Gambar</td>
<td> : <input type=file name='fupload' size=40>
<br>Tipe gambar disarankan JPG/JPEG dan ukuran lebar maks: 400 px
</td>
</tr>
<tr>
<td colspan=2>
<input type=submit class='button' value=Simpan>
<input type=button class='button' value=Batal onclick=self.history.back()>
</td>
</tr>
</table>
</form>";?>
and the PHP :
<?php
$module=$_GET[module];
$act=$_GET[act];
$produk_seo = seo_title($_POST['nama_produk']);
if (!empty($lokasi_file)){
// Cek file type
if (($tipe_file =="image/jpeg" OR $tipe_file=="image/gif" OR
$tipe_file=="image/png" OR $tipe_file=="image/wbmp" )){
UploadImage($nama_file_unik);
$query1 ="INSERT INTO sparepart(nama_produk,
produk_seo,
id_kategori,
id_kategori2,
berat,
harga,
diskon,
stok,
deskripsi,
tgl_masuk,
potongan,
gambar)
VALUES('$_POST[nama_produk]',
'$produk_seo',
'$_POST[kategori]',
'$_POST[kategori2]',
'$_POST[berat]',
'$_POST[harga]',
'$_POST[diskon]',
'$_POST[stok]',
'$_POST[deskripsi]',
'$tgl_sekarang',
'$_POST[potongan]',
'$nama_file_unik')";
$sql = mysql_query($query1);
if (!sql) {
die('there is an error');
mysql_errno($sql).":".mysql_error($sql);
} else {
echo "success bro!";
}
}
else
{
$query2 = "INSERT INTO sparepart(nama_produk,
produk_seo,
id_kategori,
id_kategori2,
berat,
harga,
diskon
stok,
deskripsi,
potongan,
tgl_posting)
VALUES('$_POST[nama_produk]',
'$produk_seo',
'$_POST[kategori]',
'$_POST[kategori2]',
'$_POST[berat]',
'$_POST[harga]',
'$_POST[diskon]',
'$_POST[stok]',
'$_POST[deskripsi]',
'$_POST[potongan]',
'$tgl_sekarang')";
$sql=mysql_query($query2);
if(!sql) {
die('there is an error');
mysql_errno($sql).":".mysql_error($sql);
} else {
echo "success bro!";
}
}
I want to know why between the 2 same codes, only 1 works and the other does not echo any error but not working.
I am using mysqli_* in my real project. I just felt more comfortable using Mysql_* when writing this question so thank you for warning me about mysql_* being deprecated.