banner_manager.php

<?php
	
	include ("includes/koneksi.php");


   //$_REQUEST['simpan'] = isset($_POST['simpan']) ? $_POST['simpan'] : '';
   //$_REQUEST['link'] = isset($_POST['link']) ? $_POST['link'] : '';
   //$_REQUEST['gambar'] = isset($_POST['gambar']) ? $_POST['gambar'] : '';
   //$_REQUEST['id'] = isset($_POST['id']) ? $_POST['id'] : '';	


	//SIMPAN DATA
	if (isset($_REQUEST['simpan'])){
		$id = $_REQUEST['id'];
		$link = mysql_real_escape_string($_REQUEST['link']);
		$gambar = $_REQUEST['gambar'];
		}
		
		//Cek apakah ada file yang diupload
		if((!empty($_FILES['uploaded_file'])) && ($_FILES['uploaded_file']['error'] == 0)){
			//$gambar = uploadPicture('uploaded_file');
		
			$target_path = "Images/";

			$target_path = $target_path . basename( $_FILES['uploaded_file']['name']); 

			$gambar = $target_path; 
			
			if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target_path)) {
    			echo "The file ".  basename( $_FILES['uploaded_file']['name']). 
   			" has been uploaded";
			
			// I add this to test insert data
			//mysql_query("INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')");
			
			} else{
 		   echo "There was an error uploading the file, please try again!";
			}

		}
		
		if (empty($id)){
			$sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";
		}else{
			$sqlstr = "UPDATE banner SET link = '".$link."',gambar = '".$gambar."' WHERE id =".$id;
		
		$result = mysql_query($sqlstr) or die(mysql_error());
				
		$confirmation = ($result)? "Data telah tersimpan.":"Gagal menyimpan data.";
		$gambar = "";
		$link = "";
		$id = "";
		}

Notice: Undefined variable: link in C:\xampp\htdocs\php_template2\banner_manager.php on line 48

Notice: Undefined variable: gambar in C:\xampp\htdocs\php_template2\banner_manager.php on line 48


line 48 is: $sqlstr = "INSERT INTO banner(link, gambar) VALUES('".$link."','".$gambar."')";


Why the error appears?

Recommended Answers

All 4 Replies

$gambar probably wasn't defined (it has no value).

$gambar = $target_path;

Is this not enough? It suppose to capture an uploaded picture path and store it in database.

In my opinion, the real problem is that the variable is not in proper type. The link and image you initialized is an array while you try to use single value from it which means that the sql query cannot get proper information from it.

any concrete example for the alternative solution ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.