Reputation: 1
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.
Upvotes: 0
Views: 152
Reputation: 122
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.'
Upvotes: 0
Reputation: 10879
There are several issues with your code:
'<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)echo "</a href>";
- you cannot have any attributes on a closing HTML tag. </a>
is enough to close the opened tag.<td>
before the <a>
, but the <a>
was opened inside the <td>
, so you'll have to close it in reverse order as well.Upvotes: 3
Reputation: 1481
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.
Upvotes: 0