0

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?

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by davy_yg
0

$gambar = $target_path;

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.