Displaying my home page pics

Hi,

i have currently built a simple web form to upload pictures along with some description which is then stored on my server(pics) and mysql db(description) and is then redisplayed on a new page, homepage.html.php. The displaying of my pictures ONLY happens when i have submit a picture.

Now, whenever i go to my browser and manually type the address of my homepage.html.php i.e http://localhost/Shanghai2010/homepage.html.php, i don’t see my pictures but rather a blank screen. Is there a way for me to view my homepage.html.php WITHOUT having to always submit a picture? because there will be times where i will need to deal with the design e.g css of my page or just simply view my pics.

Hope that is quite clear.

Here is some code for my homapage.html.php in case u need to see it.


<p>
			 
			  
		     <?php
			     if( isset($images) )
			    {
				   
				   echo '<table align="center">';
				   
				   $step = 2; // Columns
				   // Big for loop represents 1 whole image
				   for($i = 0; $i < count($images); $i+=$step)
				   {
					  // For loop for picture
					  echo '<tr>';
					  for($j = 0; $j < $step; $j++)
					  { 
						 if(isset($images[$i+$j]) )
						 {
							echo '<td><img src="./images/'.$images[$i+$j]['Filename'].'" width="250" height="250" ></td>';	
						 }
					  }
					  echo '</tr>';
					  // For loop for description
					  echo '<tr>';  
					  for($j=0; $j < $step; $j++)
					  {
						 
						if(isset($images[$i+$j]) )
						 {
							
							// Error here on this line somewhere???
							echo '<td><b>Description:</b>'.$images[$i+$j]['Description'] ."<br></td>";
								
						 }
 
					  }
					  echo '</tr>';		
				   }   
				   echo '</table>';   
			    }
		     ?>
		</p>


and here is some code fragment from my index.php


if(!isset($_FILES['photo']))
{
    include 'imageuploadform.html.php';
        
}
if(isset($_POST['action']) and $_POST['action'] == 'upload')
{  
    $description = mysqli_real_escape_string($link, $_POST['description']);
    $category = mysqli_real_escape_string($link, $_POST['category']);
    $file = ($_FILES['photo']['name']);
    
    $target = './images/';
    $target .= basename($_FILES['photo']['name']);
    
    //print_r($_FILES['photo']);
    
    // Check if file was uploaded
    if(!is_uploaded_file($_FILES['photo']['tmp_name']))
    {
        $error = 'There was no file uploaded';
        include $_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php';
        exit();
    }
....
 

Your views would be greatly appreciated

Hi, i’m such a noob, i realised what i should have done in the first place, what i should have done was simply copy and past the following code:



 include $_SERVER['DOCUMENT_ROOT'] . '/includes/shanghai_db.inc.php';
       $result = mysqli_query($link, "SELECT * FROM image_detail");
       
 
        
   if(!$result )
    {
        $error = 'Error fetching image data from database';
        include 'error.html.php';
        exit();    
    }
          
    while ($row = mysqli_fetch_array($result))
    {
        $images[] = array('Filename' => $row['Filename'], 'Description' => $row['Description'], 'Category' => $row['Category']);
    }
   

into my “showall” if statment and run “showall” in my brower because that is waht i actaully wanted. The only thing i did not think about was adding the “showall” $_GET variable thing which i have done now. Now can easily comment the upload file code and simply show my website and whenever i need to upload a photo, just uncomment it.

updated code:


include $_SERVER['DOCUMENT_ROOT'] . '/includes/magicquotes.inc.php';
include $_SERVER['DOCUMENT_ROOT'] . '/includes/shanghai_db.inc.php';
if (isset($_GET["showall"]))
{
    include $_SERVER['DOCUMENT_ROOT'] . '/includes/shanghai_db.inc.php';
       $result = mysqli_query($link, "SELECT * FROM image_detail");
       
 
        
   if(!$result )
    {
        $error = 'Error fetching image data from database';
        include 'error.html.php';
        exit();    
    }
          
    while ($row = mysqli_fetch_array($result))
    {
        $images[] = array('Filename' => $row['Filename'], 'Description' => $row['Description'], 'Category' => $row['Category']);
    }
    
    
    
    include 'homepage.html.php';
    
    
}
....



Sorry for any inconvenience guys, much appreciated for the help aswell.
Thnks

Yeah, doh… like so…

$sql = “SELECT * FROM image_detail”;
while ($result = mysql_fetch_object(mysql_query($sql))) {

You dont have to register a domain, you just need to run “?showall” after the root as you’ve done above…

Could you paste your whole php contents so we can solve it quickly.
You can do that here->http://paste.andrewodendaal.com/

Try paste this on line 12 just before ->“if(isset($_GET[“homepage”]) )”:

if (isset($_GET["showall"])) {
    $sql = "SELECT * FROM image_detail";
    while ($result = mysql_fetch_object($sql)) {
        echo "Filename $result-&gt;uploadname, Category = $result-&gt;uploadcat, Description = $result-&gt;uploaddesc &lt;br/&gt;\

";
}
}

You will then need to load the url with a get var like so: http://mydomain.com/?showall

mysql_fetch_object() accepts a mysql result instance not the query string. You will first need to actually run the query and than pass the return value to mysql_fetch_object() to retrieve each row in the result set. That may not be the only problem but its the most evident one looking at the code.

yese ofcourse i can, http://paste.andrewodendaal.com/4c7f7e7b29d2d.html
hope that helps

I added the code, but not sure about your last comment, i typed in my browser: http://localhost/Shanghai2010/?showall, and i got a warning message

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in C:\\wamp\\www\\Shanghai2010\\index.php on line 15



include $_SERVER['DOCUMENT_ROOT'] . '/includes/magicquotes.inc.php';
include $_SERVER['DOCUMENT_ROOT'] . '/includes/shanghai_db.inc.php';
if (isset($_GET["showall"]))
{
    $sql = "SELECT * FROM image_detail";
    while ($result = mysql_fetch_object($sql))
    {
        echo "Filename $result->uploadname, Category = $result->uploadcat, Description = $result->uploaddesc <br/>\
";
    }
}

if(isset($_GET["homepage"]) )
{
    include 'homepage.html.php';
}

.....




can you tell me what you mean in your last comment please. Do i need to register the domain?

In your first codeblock you basically did it right there.
If you want the same page to simply view the images without an upload required, then just do it within a isset($_GET[“whatever”]) block.

e.g.:

<?php
if (isset($_GET[“whatever”]))

What is $images ? Is that something you aren’t telling us about?

Hi, i added the following code to the top of my index.php file:




if(isset($_GET["displayhomepage"]))
{
    include 'homepage.html.php';
}


and it does not seem to display. $images is a variable meant to hold an array of images from my mysql db :


while ($row = mysqli_fetch_array($result))
    {
        $images[] = array('Filename' => $row['Filename'], 'Description' => $row['Description'], 'Category' => $row['Category']);
    }

i was not sure if i should added that because i wasn’t sure how code of my index.php file i had to show in order for it to be useful.