Page 2 of 3
Posted: Thu Feb 15, 2007 1:42 pm
by RobertGonzalez
Ok, your turn. Write some code that will work.
Code: Select all
<?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
}
?>
Posted: Thu Feb 15, 2007 1:52 pm
by phpflixnewbie
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?
Posted: Thu Feb 15, 2007 1:54 pm
by RobertGonzalez
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.
Posted: Thu Feb 15, 2007 2:00 pm
by phpflixnewbie
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'
Please advise.
Code: Select all
<?php
$show_detail = false;
if (isset($_GET['id']))
{
$Host = "localhost"; //you can use IP address instead of localhost
$User = "username";
$Password = "password";
$Database = "databasename";
$Link_ID=mysql_pconnect($Host, $User, $Password);
if (!$Link_ID)
{
echo "Failed to connect to Server=".$Host;
return 0;
}
else
{
# echo "<B>Successfully to connected to Server </B>" .$Host;
}
if (!@mysql_select_db($Database,$Link_ID))
{
# echo "<br>Cannot use database= " .$Database;
}
else
{
# echo "<br> Successfully connected to database= ";
}
$dvd_id = mysql_real_escape_string($_GET['id']);
$sql = "select dvd_id, dvd_title, dvd_plot from dvd_details, dvd_titles where dvd_titles.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 'Title: ' . $dvd_detail['dvd_title'] . '<br />';
echo 'Plot: ' . $dvd_detail['dvd_plot'] . '<br />';
}
else
{
// Will add code for master/main table here
}
?>
Posted: Thu Feb 15, 2007 2:03 pm
by phpflixnewbie
Nevermind i found the problem, just edited sql query to:
Code: Select all
$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

Posted: Thu Feb 15, 2007 2:49 pm
by phpflixnewbie
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.
Code: Select all
<?php
$show_detail = false;
if (isset($_GET['id']))
{
$$Host = "localhost"; //you can use IP address instead of localhost
$User = "username";
$Password = "password";
$Database = "databasename";
$Link_ID=mysql_pconnect($Host, $User, $Password);
if (!$Link_ID)
{
echo "Failed to connect to Server=".$Host;
return 0;
}
else
{
# echo "<B>Successfully to connected to Server </B>" .$Host;
}
if (!@mysql_select_db($Database,$Link_ID))
{
# echo "<br>Cannot use database= " .$Database;
}
else
{
# echo "<br> Successfully connected to database= ";
}
$dvd_id = mysql_real_escape_string($_GET['id']);
$sql = "select dvd_titles.dvd_id, dvd_title, dvd_plot, image_path from dvd_details, dvd_titles, dvd_coverart where dvd_titles.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 '<img src="$dvd_detail['image_path']"';
echo '<p>'.'Title: ' . $dvd_detail['dvd_title'] . '</p>';
echo '<p>'.'Plot: ' . $dvd_detail['dvd_plot'] . '</p>';
}
else
{
// Will add code for master/main table here
}
?>
Posted: Thu Feb 15, 2007 6:48 pm
by RobertGonzalez
Follow the lead of the other code...
Code: Select all
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>';
}
Posted: Fri Feb 16, 2007 11:07 am
by phpflixnewbie
Hi everah,
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.
Posted: Fri Feb 16, 2007 11:30 am
by RobertGonzalez
View the source of the output html and post a few lines of that so we can see what is being output.
Posted: Fri Feb 16, 2007 11:34 am
by phpflixnewbie
Heres the output HTML for the main part of the page:
Code: Select all
<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>
Posted: Fri Feb 16, 2007 11:53 am
by RobertGonzalez
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.
Posted: Fri Feb 16, 2007 12:10 pm
by phpflixnewbie
Removed the space from the directory and the path in the database, refreshed the page, but image still not displaying

Posted: Fri Feb 16, 2007 12:34 pm
by RobertGonzalez
Change your path separator to '/' instead of '\'.
Posted: Fri Feb 16, 2007 1:33 pm
by phpflixnewbie
That worked! Thankyou again!

(Hugs Everah)
Posted: Fri Feb 16, 2007 4:18 pm
by RobertGonzalez
Glad I could help.