banner_manager.php

<?php

	//if (!$_SESSION['login']){
	//	echo "Anda tidak berhak mengakses halaman ini.";
	//	exit();
	//}
	
	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'])){
		$link = mysql_real_escape_string($_REQUEST['link']);
		$id = $_REQUEST['id'];
		$gambar = $_REQUEST['gambar'];
		}
		
//Cek apakah ada file yang diupload
//if((!empty($_FILES['uploaded_file'])) && ($_FILES['uploaded_file']['error'] == 0)){
if((!empty($_FILES['uploaded_file']))){
//$gambar = uploadPicture('uploaded_file');
$gambar = $_FILES('uploaded_file');
	}
		
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 = "";
}
		
	
	//EDIT / DELETE MODE
if (!empty($_REQUEST['id']) && !empty($_REQUEST['mode'])){
		if ($_REQUEST['mode'] == 'delete'){
			$result = mysql_query("DELETE FROM banner WHERE id=".$_REQUEST['id']) or die(mysql_error());
			$confirmation = ($result)? "Data telah terhapus.":"Gagal menghapus data.";
		}elseif ($_REQUEST['mode'] == 'edit'){
			$result = mysql_query("SELECT * FROM banner WHERE id=".$_REQUEST['id']) or die(mysql_error());
			$data = mysql_fetch_array($result);
			$id = $data['id'];
			$link = $data['link'];
			$gambar = $data['gambar'];
		}
	}
	?>

<div align="center">
	<div style="width:700px;text-align:left;padding-top:25px;">
	<div class="pageTitle">Banner Manager</div>
	<?php //echo $confirmation; ?><br/>
	<form method="post" enctype="multipart/form-data" action="<?php $_SERVER['http://localhost/php_template2/PHP_SELF']?>">
		<table width="700px" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td>Link</td>
			<td>
<input type="text" name="link" value="<?php echo $link; ?>"/> Contoh: http://www.garudanews.co.cc
<input type="hidden" name="id" value="<?php echo $id; ?>"/>
			</td>
		</tr>
		<tr>
			<td>Gambar</td>
			<td><input type="file" name="uploaded_file"/></td>
		</tr>
		<tr>
			<td colspan="2">
				<?php
				if (!empty($_REQUEST['id'])){
				?>
					<img src="<?php echo $gambar;?>" alt="gambar"/>
					<input type="hidden" name="gambar" value="<?php echo $gambar; ?>"/>
				<?php
				}
				?>
			</td>
		</tr>
		<tr>
			<td colspan="2"><input type="submit" name="simpan" value="Simpan"/></td>
		</tr>
	</table>
	</form>
	<hr/>
	
<table width="400px" border="1" cellpadding="2" cellspacing="0">
<tr>
	<th>Banner</th>
	<th>Action</th>
</tr>
<?php
//LOAD USER
$result = mysql_query("SELECT * FROM banner");
while ($data = mysql_fetch_array($result)){
?>
	<tr>
		<td><?php echo $data['link'];?></td>
		<td>
			<a href="file:///C|/xampp/htdocs/garuda_news/banner_manager.php?id=<?php echo $data['id']; ?>&amp;mode=delete">Hapus</a> | 
			<a href="file:///C|/xampp/htdocs/garuda_news/banner_manager.php?id=<?php echo $data['id']; ?>&amp;mode=edit">Edit</a>
		</td>
	</tr>
		<?php
		}
		?>
	</table>
	</div>
</div>

Banner Manager


Link [__________] Contoh: http://www.garudanews.co.cc
Gambar [____________] [Browse]

[Simpan]

--------------------
Banner I Action I

I basically wonder why after I filled in link and gambar(translate: picture), and click
simpan (translate: Submit), the form shows me this:

Access forbidden!
You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403


Why is it? I already try two different picture with *.jpg format.

Recommended Answers

All 11 Replies

I changed it to: <?php $_SERVER?>

Now this is a new error:

Fatal error: Function name must be a string in C:\xampp\htdocs\php_template2\banner_manager.php on line 28

line 28: $gambar = $_FILES('uploaded_file');

I changed it to square bracket.

Now when I press Simpan nothing happen. It suppose to capture the link address and picture.

If you are trying to insert an entire file into the database, you'll have to move it first.

Is it possible to insert picture to the databases? I thought, it save the picture link to the databases and save/move the picture to a certain folder. or perhaps it basically the same thing.

How to do so?

banner_manager.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'])){
		$link = mysql_real_escape_string($_REQUEST['link']);
		$id = $_REQUEST['id'];
		$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['uploadedfile']['name']); 

			$gambar = $target_path;
			
			if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    			echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
   			" has been uploaded";
			} 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;

Notice: Undefined index: uploadedfile in C:\xampp\htdocs\php_template2\banner_manager.php on line 30

Notice: Undefined index: uploadedfile in C:\xampp\htdocs\php_template2\banner_manager.php on line 34
There was an error uploading the file, please try again!

replace $_FILES with $_FILES in your code.

Thanks, the file has been moved. It's written: The file Air Freshner.jpg has been uploaded.

Yet, when I checked in the database phpmyadmin, the database is still empty.

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.