0

I've created a database where you can add various info. I've then created a site.php file, that has the purpose to redirect the person to the content related to the image they're clicking on.

I've got a site.php that works fine. The part that I can't get to work, is linking correctly to the site.php?id=IDhere

I've got this piece of code to echo out all the images in my database, and they should link to the PlaceID. But I can't get the link to post the PlaceID variable in my link. I've tried echoing out the variable, and it's the correct one, so the variable I'm defining is correct. How should the link look like?

<?php
displayimage();

  function displayimage()
    {
      include('includes/connectdb.php');

      if(isset($_GET["category"])) { // Checks if category is set
          $qry="SELECT place.id AS placeid, pictures.name, pictures.image, pictures.place_id
                FROM pictures
                INNER JOIN place
                ON pictures.place_id = place.id
                INNER JOIN placecategory
                ON place.id = placecategory.place_id
                INNER JOIN category
                ON placecategory.category_id = category.id
               WHERE placecategory.category_id = ".$_GET["category"]; // category id

        $result=mysqli_query($dbc,$qry);
        while($row = mysqli_fetch_array($result))
        {
          $PlaceID = $row['placeid'];
          //var_dump($row); 
          echo '<a href="site.php?id=$PlaceID"><img class="col-lg-3 col-md-4 col-sm-6 col-xs-12 img-responsive galleryimg" src="data:image;base64,'.$row["image"].' "></a> ';
        }
      }
      }
      mysqli_close($dbc); 
    }
  ?>
Stephan Olsen
  • 1,623
  • 1
  • 14
  • 29

1 Answers1

1

$PlaceID is in apostrophes so is treated as string, not as variable: What is the difference between single-quoted and double-quoted strings in PHP?

corrected:

echo '<a href="site.php?id='.$PlaceID.'"><img class="col-lg-3 col-md-4 col-sm-6 col-xs-12 img-responsive galleryimg" src="data:image;base64,'.$row["image"].' "></a> ';
Community
  • 1
  • 1
pmaniora
  • 76
  • 5