PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$show_detail = false;
if (isset($_GET['id']))
{
$dvd_id = mysql_real_escape_string($_GET['id']);
$sql = "select `dvd_id`, `dvd_plot` from `dvd_details` where `dvd_id` = $dvd_id";
if (!$result = mysql_query($sql))
{
die('Could not get the selected DVD using ' . $sql . ': ' . mysql_error());
}
$dvd_detail = mysql_fetch_array($result);
if (!empty($dvd_detail))
{
$show_detail = true;
}
}
if ($show_detail)
{
// $dvd_detail houses the information in the detail
echo 'The ID of this DVD: ' . $dvd_detail['dvd_id'] . '<br />';
echo 'The plot of this DVD: ' . $dvd_detail['dvd_plot'] . '<br />';
}
else
{
// Will add code for master/main table here
}
?>
WERHOOOO! Just tested the ammended code and added my database connection strings and it worked!!
Still just need to add my master table code, but surely there will always be a match of details for the ID?
Not surely, since you are passing the ID through GET. There is nothing to stop someone from passing url?id=MyStringeHands. Always validate, and only show a detail if there was actually a record found, after validating the $_GET['id'] var.
Everah, many thanks for the help. I am now trying to edit the code so it outputs exactly what im after. I would like it to print out the Title name, but i keep getting the error:
'Could not get the selected DVD using select dvd_id, dvd_title, dvd_plot from dvd_details, dvd_titles where dvd_titles.dvd_id = 1: Column 'dvd_id' in field list is ambiguous'
$sql = "select dvd_titles.dvd_id, dvd_title, dvd_plot from dvd_details, dvd_titles where dvd_titles.dvd_id = $dvd_id";
So far I only have one title which has detail information, i need to add details to other titles so i can fully test it on any random ID.
Many thanks for all the help guys
Just one last thing on this issue guys, how do i echo/print out the coveart images. I have stored their URLs in the database and added them to the sql query, ive attempted the echo statement below, but no joy.
Please advise.
if ($show_detail)
{
// $dvd_detail houses the information in the detail
// This has a few problems, can you spot the difference between it and
// echo '<img src="$dvd_detail['image_path']"';
// This one?
echo '<img src="' . $dvd_detail['image_path'] . '" />';
echo '<p>'.'Title: ' . $dvd_detail['dvd_title'] . '</p>';
echo '<p>'.'Plot: ' . $dvd_detail['dvd_plot'] . '</p>';
}
I see from your ammendment that i was missing the dots, the closing image tag and quote marks were in the wrong place, however the image is still not displaying.
The URLs in the database are stored as \coverart images\filename.jpg and i also tried localhost\coverart images\filename.jpg.
Please advise.
<div id="details">
<img src="\coverart images\kingofthehills04.jpg" /><p><b>Title:</b>Beavis And Butt-Head Do America</p><p><b>Plot:</b>Our two adolescent heroes embark on an epic journey across america to recover their precious stolen television.
On their travels they come across a murderous smuggler of a deadly virus, an FBI agent with a partiality for cavity searches and ex-Motley Crue roadies.
Can the Great Cornholio save the day? Ofcourse they can! (or maybe not).</p>
</div>
There is a space in your image path. That is likely to kill it. You should either get rid of the space or run the path variable through urlencode() so that the spaces get transposed to something usable. I would suggest just getting rid of the space however.