Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Notice: Undefined index: id_buku in D:\xampp\htdocs\tokobuku\page\admin\e_book.php on line 3

Notice: Undefined index: kategori in D:\xampp\htdocs\tokobuku\page\admin\e_book.php on line 10

Notice: Trying to access array offset on value of type null in D:\xampp\htdocs\tokobuku\page\admin\e_book.php on line 13

What I have tried:

<?php
include"../../config.php";
	$id_buku = $_POST['id_buku'];
	$judul = $_POST['judul'];
	$penerbit = $_POST['penerbit'];
	$pengarang = $_POST['pengarang'];
	$halaman = $_POST['halaman'];
	$harga = $_POST['harga'];
	$stok = $_POST['stok'];
	$kategori= $_POST['kategori'];
	$qryid = mysqli_query($con,"SELECT * FROM kategori where kategori='$kategori'");
	$data = mysqli_fetch_array($qryid);
	$id_kategori = $data['id_ketegori'];

@$message		= '';
$valid_file		= true;
$max_size		= 1024000;


if($_FILES['gambar']['name']){
	
	if(!$_FILES['gambar']['error']){

		$new_file_name = strtolower($_FILES['gambar']['tmp_name']); 
		if($_FILES['gambar']['size'] > $max_size)
			$valid_file	= false;
			$message	= 'Maaf, file terlalu besar. Max: 1MB';
		}
	
		$image_path = pathinfo($_FILES['gambar']['name'],PATHINFO_EXTENSION); 
		$extension = strtolower($image_path); 

		if($extension != "jpg" && $extension != "jpeg" && $extension != "png" && $extension != "gif" ) {
			$valid_file = false;
			$message	= "Maaf, file yang diijinkan hanya format JPG, JPEG, PNG & GIF. #".$extension;
		}



	
		if($valid_file == true)
		{
		
			$rename_nama_file	= date('YmdHis');
			$nama_file_baru		= $rename_nama_file.'.'.$extension;


			
			mysqli_query($con,"UPDATE buku set judul='$judul',id_ketegori='$id_kategori',pengarang='$pengarang',penerbit='$penerbit',halaman='$halaman',harga='$harga', gambar='$nama_file_baru', stok='$stok' where id_buku='$id_buku'");
		
			move_uploaded_file($_FILES['gambar']['tmp_name'], '../../gambar/'.$nama_file_baru);
			header("location:index.php?page=buku");
		}
	}
	
	else
	{

		$message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['gambar']['error'];
	}
?>
Posted
Updated 23-May-21 16:35pm

1 solution

The two firs messages indicate that the value for those indices is not set. Before fetching the values, you can use PHP: isset - Manual[^] to investigate if the value is actually set or not.

The third message seems like you might have a typo. Instead of
$data['id_ketegori'];

Should it be
$data['id_kategori'];

Then about the query, always use parameterized queries. Using the values directly leaves you wide open to SQL injection - Wikipedia[^]

For parameterized queries, have a look at for example PHP: Prepared Statements - Manual[^] and PHP: mysqli::prepare - Manual[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900