Image_gallery.php

$con = mysql_connect('localhost', 'root', '');
	  
	  if (!$con) {
    	die('Could not connect: ' . mysql_error());
		}
		echo '<p align="left">Connected successfully';

	  
	   $db_selected = mysql_select_db("template", $con);

	   if (!$db_selected)
  		{
  		die ("Can't use template : " . mysql_error());
  		}  	
		
		
		
	//Save File
	if (isset($_REQUEST['save'])){
		if (empty($_FILES['uploaded_file'])){
			echo "Tidak ada file yang diupload.";
		}else{
			$title = mysql_real_escape_string($_REQUEST['title']);
			$uploadPath = uploadPicture("uploaded_file");
			
			$sqlstr = "INSERT INTO image_gallery(title, path) ";
			$sqlstr .= "VALUES('".$title."','".$uploadPath."')";
			
			$result = mysql_query($sqlstr) or die(mysql_error());
			
			$confirmation = ($result)? "Gambar telah tersimpan." : "Gagal menyimpan data.";
		}
	}
	
	$limit = 25;
	
	//Get total records
	$resTotal = mysql_query("SELECT COUNT(id) AS total FROM image_gallery") or die(mysql_error());
	$data = mysql_fetch_object($resTotal);
	$totalRec = $data->total;
	
	//Get total pages
	$totalpaging = ceil($totalRec / $limit);
		
	$paging = (!empty($_REQUEST['paging']) && $_REQUEST['paging'] != 0)? $_REQUEST['paging'] : 1 ;
	
	//Set record position
	if (empty($paging) || $paging ==0) {
		$position = 0;
		$paging=1;
	}	
	else
		$position = ($paging -1 ) * $limit;
	
	$result = mysql_query("SELECT * FROM image_gallery LIMIT $position, $limit") or die(mysql_error());
	$numRows = (mysql_num_rows($result) > $limit)? 20 : mysql_num_rows($result) ;
	if ($numRows > 0){
?>
<div align="center">
	<div style="width:700px;text-align:left;padding-top:25px;">
		<?php 
			echo $confirmation;
		?>
		<link rel="stylesheet" href="file:///C|/xampp/htdocs/garuda_news/css/lightbox.css" type="text/css" media="screen" />
		<script src="file:///C|/xampp/htdocs/garuda_news/js/prototype.js" type="text/javascript"></script>
		<script src="file:///C|/xampp/htdocs/garuda_news/js/scriptaculous.js?load=effects,builder" type="text/javascript"></script>
		<script src="file:///C|/xampp/htdocs/garuda_news/js/lightbox.js" type="text/javascript"></script>
		<script type="text/javascript" src="file:///C|/xampp/htdocs/garuda_news/js/reflection.js"></script>
		<table width="700px" border="0" cellspacing="2" cellpadding="2">
			<?php
			$i = 0;
			//while ($data = mysql_fetch_object($result)){
				for ($rows = 1; $rows<=5; $rows++){
					echo "<tr>";
					for ($cols=1; $cols<=5;$cols++){
						if ($i >= $numRows) break;
						echo '<td style="text-align:center;">';
							$data = mysql_fetch_object($result);
							echo '<div style="width:100px;font-family: verdana; font-size: 11px;">',$data->title;
							echo '<a href="'.$data->path.'" rel="lightbox[roadtrip]">';
							echo '	<span style="border:0px;"><img border="0px" class="reflect" src="'.$data->path.'" width="100" height="100" alt="'.$data->title.'" /></span>';
							echo '</a></div>';							
						echo "</td>";
						$i++;
					}
					echo "</tr>";
				}
			//}
			?>
			<tr>
				<td colspan="4" style="text-align:center;">
					<?php
					if ($totalpaging > 0){
						//Write first and prev navigation
						if ($paging > 1){
							$prevpaging = 0;
							echo '<a style="text-decoration:none;" href="?page=image_gallery&paging=1"><<< First</a> ';
						}else{
							echo "<<< First ";
						}
						
						if ($paging > 1){
							$prevpaging = $paging-1;
							echo '<a style="text-decoration:none;" href="?page=image_gallery&paging='.$prevpaging.'"><< Prev</a> ...';
						}else{
							echo "<< Prev ";
						}

						//write number navigation
						if ($paging > 1){
							$beforepaging = $paging -1 ;
							echo '<a style="text-decoration:none;" href="?page=image_gallery&paging='.$beforepaging.'">'.$beforepaging.'</a> ';
						}
						if ($paging != 0)	echo $paging;
						
						if ($paging < $totalpaging && $paging != 0){
							$nextpaging = $paging + 1 ;
							echo ' <a style="text-decoration:none;" href="?page=image_gallery&paging='.$nextpaging.'">'.$nextpaging.'</a>';
						}
						
						//write next and last navigation
						if ($paging < $totalpaging){
							$nextpaging = $paging + 1;
							echo '...<a style="text-decoration:none;" href="?page=image_gallery&paging='.$nextpaging.'">Next >></a>';
						}else{
							echo " Next >>";
						}
						
						$pagingDiff = $totalpaging - ($paging - 1);				
						if ($pagingDiff > 1){					
							echo ' <a style="text-decoration:none;" href="?page=image_gallery&paging='.$totalpaging.'">Last >>></a>';
						}else{
							echo " Last >>>";
						}
					}
					?>
				</td>
			</tr>
		</table>
<?php
	}
	
?>
	<br/>
	<form method="post" enctype="multipart/form-data" action="<?php $_SERVER['file:///C|/xampp/htdocs/garuda_news/PHP_SELF']?>">
		<table width="400px" border="0" cellpadding="0" cellspacing="0">
			<tr>
				<td>Judul</td>
				<td><input type="text" name="title" value="<?php echo $imgDt->title;?>"</td>
			</tr>
			<tr>
				<td>File gambar</td>
				<td><input type="file" name="uploaded_file"/></td>
			</tr>
			<tr>
				<td colspan="2"><img src="<?php echo $imgDt->path;?>" alt="<?php echo $imgDt->title;?>"/></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" name="save" value="Save"/></td>
			</tr>
		</table>
	</form>
	</div>
</div>

Notice: Trying to get property of non-object in C:\xampp\htdocs\php_template2\image_gallery.php on line 159 </b><br />


line 159: <td colspan="2"><img src="<?php echo $imgDt->path;?>" alt="<?php echo $imgDt->title;?>"/></td>

Why is it?

$imgDt is not an instance of an object. You also did not show any code where $imgDt is actually set.

It's someone else file that I am trying to modify. A tutorial file. If it's incomplete, how to make it works? Should I set a class, or something else to define the path.

The form basically needs to take the picture that I upload and store it in /resources and also save the title of the picture at the same time. It seems like this is the only file the tutorial cd gives me for the image_gallery (image_gallery.php).

I basically building a private website by modifying the tutorial file.

Another clue:

Image_gallery table consists of the following fields:

id, title, path

Well, it looks like you're setting $data on line 79. It looks like the value of $data mirrors how you're trying to use $imgDt.

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.