0

I need to make a movie rater website and on the front page it has the ten most recently added movies. Whenever you click on the movie title its supposed to take you to another page where you can see more info on the movie. I cant seem to get my a href to properly send any of the data to the other page.

code for displaying my homepage

while($row = $result->fetch()){

$MovieName = $row['name'];
$MoviePic = $row['picture'];


echo "<div align=center>";
if($i==1){
    echo '<tr>';
}
$id = $row['MovieId'];
echo '<td><a href = "MovieInfo.php?id = $id"> <img src="data:image/jpeg;base64,'.base64_encode( $MoviePic).'"width = 115 height = 150 name = $MovieName/>';

echo "<br>";
echo $MovieName, '</td>';
echo "</a href>";
echo "<br>";

$i = $i + 1;  
if($i==4){
    echo '</tr>';
    $i=1;
    }
}

code from the second webpage

<?php
require('DBConnect.php');
echo "<div align=center>";
if(isset($_GET['id'])){
    $Name = $_GET['id'];
}
else{
    $Name = 'no';
}
echo $Name;

currently, I'm just testing with the movie's id but no data is being sent to the new page.

1
  • Did any of the answers below answers solve your question? If so, please mark the one that you find most helpful as accepted by clicking the check mark icon next to it (you can only accept one answer). If not, you can use the comments to request more information. Commented Nov 13, 2019 at 8:12

3 Answers 3

3

There are several issues with your code:

  1. remove the spaces before and after the equal sign in your URL (you also don't need them in your HTML attribute/value pairs, and while it may not be invalid, it's not common to have those)
  2. PHP variables are not resolved in single quote strings. You need to concatenate the variable into your single quote string like this: '<td><a href = "MovieInfo.php?id=' . $id . '"> <img...' (and the same with name = $MovieName, where you should also add double quotes around the attribute value)
  3. echo "</a href>"; - you cannot have any attributes on a closing HTML tag. </a> is enough to close the opened tag.
  4. You are closing the <td> before the <a>, but the <a> was opened inside the <td>, so you'll have to close it in reverse order as well.
Sign up to request clarification or add additional context in comments.

Comments

0

You will need to do an additional query on the page load for your movie page. Something like SELECT * FROM movies WHERE id = MOVIE_ID. I strongly suggest you use PDO to do your queries with prepared statements to avoid SQL injection.

1 Comment

Thank you for the feedback. I had another SQL query on that page but I have it commented out till I can get everything else to work but thank you for the advice!
0

Issue is with proper concatenation of id in href. $id is being read as string rather than PHP variable. Replace href with the following line:

href = "MovieInfo.php?id='.$id.'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.