Got a fatal error in my php code, trying to make catalog website
Fatal error: Uncaught mysqli_sql_exception: 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 'id']?>', 'Ayam Utuh 1 Potong ', '20000', ' at line 3 in C:laragonwwwkatalogtambah-produk.php:102 Stack trace: #0 C:laragonwwwkatalogtambah-produk.php(102): mysqli_query(Object(mysqli), 'INSERT INTO mas...') #1 {main} thrown in C:laragonwwwkatalogtambah-produk.php on line 102
Here is my code on PHP
<?php
if(isset($_POST['submit'])){
//contains input from form//
$kategori = $_POST['kategori'];
$nama = $_POST['nama'];
$harga = $_POST['harga'];
$deskripsi = $_POST['deskripsi'];
$supplier = $_POST['supplier'];
$stok = $_POST['stok'];
//contains uploaded files//
$filename = $_FILES['foto']['name'];
$tmp_name = $_FILES['foto']['tmp_name'];
$type1 = explode('.', $filename);
$type2 = $type1[1];
$newname = 'produk' .time().'.'.$type2;
//Contains allowed images formats//
$tipe_diijinkan = array('jpg', 'jpeg', 'png', 'webp');
move_uploaded_file($tmp_name, './produk/' .$newname);
$insert = mysqli_query($koneksi, "INSERT INTO master VALUES (
null,
'".$kategori."',
'".$nama."',
'".$harga."',
'".$deskripsi."',
'".$newname."',
'".$supplier."',
'".$stok."',
null
)
" );
if($insert){
echo "Simpan data berhasil";
?>
For summary here is my database My master table (products)
my category table My category column
Tried to change some of the variables like $kategori to $id_kategori, more errors, i dont know any solutions other than that, but i have try opens the product images file folder in my website folder, the images just adds and it is there.
New contributor
rdtyprdn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1