< ?php
// take in the id of a director and return his/her full name
function get_director($director_id) {
global $db;
$query = ‘SELECT
people_fullname
FROM
people
WHERE
people_id = ‘ . $director_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $people_fullname;
}
// take in the id of a lead actor and return his/her full name
function get_leadactor($leadactor_id) {
global $db;
$query = ‘SELECT
people_fullname
FROM
people
WHERE
people_id = ‘ . $leadactor_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $people_fullname;
}
// take in the id of a movie type and return the meaningful textual
// description
function get_movietype($type_id) {
global $db;
$query = ‘SELECT
movietype_label
FROM
movietype
WHERE
movietype_id = ‘ . $type_id;
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
extract($row);
return $movietype_label;
}
// function to calculate if a movie made a profit, loss or just broke even
function calculate_differences($takings, $cost) {
$difference = $takings - $cost;
if ($difference < 0) {
$color = ‘red’;
$difference = ‘$’ . abs($difference) . ‘ million’;
} elseif ($difference > 0) {
$color =’green’;
$difference = ‘$’ . $difference . ‘ million’;
} else {
$color = ‘blue’;
$difference = ‘broke even’;
}
return ‘ < span style=”color:’ . $color . ‘;” > ’ . $difference . ‘ < /span > ’;
}
//connect to MySQL
$db = mysql_connect(‘localhost’, ‘bp6am’, ‘bp6ampass’) or
die (‘Unable to connect. Check your connection parameters.’);
mysql_select_db(‘moviesite’, $db) or die(mysql_error($db));
// retrieve information
$query = ‘SELECT
movie_name, movie_year, movie_director, movie_leadactor,
movie_type, movie_running_time, movie_cost, movie_takings
FROM
movie
WHERE
movie_id = ‘ . $_GET[‘movie_id’];
$result = mysql_query($query, $db) or die(mysql_error($db));
$row = mysql_fetch_assoc($result);
$movie_name = $row[‘movie_name’];
$movie_director = get_director($row[‘movie_director’]);
$movie_leadactor = get_leadactor($row[‘movie_leadactor’]);
$movie_year = $row[‘movie_year’];
$movie_running_time = $row[‘movie_running_time’] .’ mins’;
$movie_takings = $row[‘movie_takings’] . ‘ million’;
$movie_cost = $row[‘movie_cost’] . ‘ million’;
$movie_health = calculate_differences($row[‘movie_takings’],
$row[‘movie_cost’]);
// display the information
echo < < < ENDHTML
< html >
< head >
< title > Details and Reviews for: $movie_name < /title >
< /head >
< body >
< div style=”text-align: center;” >
< h2 > $movie_name < /h2 >
< h3 > < em > Details < /em > < /h3 >
< table cellpadding=”2” cellspacing=”2”
style=”width: 70%; margin-left: auto; margin-right: auto;” >
< tr >
< td > < strong > Title < /strong > < /strong > < /td >
< td > $movie_name < /td >
< td > < strong > Release Year < /strong > < /strong > < /td >
< td > $movie_year < /td >
< /tr > < tr >
< td > < strong > Movie Director < /strong > < /td >
< td > $movie_director < /td >
< td > < strong > Cost < /strong > < /td >
< td > $$movie_cost < td/ >
< /tr > < tr >
< td > < strong > Lead Actor < /strong > < /td >
< td > $movie_leadactor < /td >
< td > < strong > Takings < /strong > < /td >
< td > $$movie_takings < td/ >
< /tr > < tr >
< td > < strong > Running Time < /strong > < /td >
< td > $movie_running_time < /td >
< td > < strong > Health < /strong > < /td >
< td > $movie_health < td/ >
< /tr >
< /table > < /div >
< /body >
< /html >
ENDHTML;
? > oluwafisayo 0 Newbie Poster
Edited by nav33n because: Please use [code] tags to wrap your code for easy readability.
Dani AI
Generated
Quick summary: the file will fail on parse/syntax errors first — most likely causes are the stray space in the PHP open/close tags, non-ASCII “smart” quotes everywhere (they get turned into ‘’/“”), the heredoc being written with extra spaces, and a few bad HTML/variable typos in the output. already flagged the heredoc and quoting issues; was right about formatting; was also correct that small punctuation/placement problems are the blockers.
Concrete fixes to apply now
- Use a proper PHP open tag:
<?php(no space) and close with?>if needed. - Replace all smart quotes with ASCII single/double quotes, e.g.
$_GET['movie_id']. Cast GET values to an int for queries:$id = (int) $_GET['movie_id'];. - Avoid accidental variable-variables: output
$movie_cost, not$$movie_cost. - Fix HTML table tags (
</td>, not<td/>) and remove stray spaces inside HTML tags (<span>not< span>). - Heredoc must be
echo <<<ENDHTML(no space between<<<and the label), the label must be alone on its line when starting and ending, and the closingENDHTML;must start at column 0.
Security and modernization notes
- Building SQL by concatenation is unsafe. At minimum cast numeric input to
(int). Better: use prepared statements with PDO or mysqli to prevent SQL injection and to be compatible with modern PHP (the oldmysql_*extension is removed in current PHP versions).
Quick debugging workflow
- Run a syntax check:
php -l filename.php. - Turn on errors during testing:
error_reporting(E_ALL); ini_set('display_errors', 1);. - Echo or
var_dump()the final SQL string and the fetched$rowto verify the query and data. Fix syntax first, then move to SQL/security and HTML output.
Applying those small, focused fixes in sequence will get the script to run; once it does, migrate DB access to PDO/mysqli and remove extract() in favor of explicit $row['key'] reads for clarity.
Recommended Answers
Jump to Post— pritaeas 2,276
echo < < < ENDHTMLshould beecho <<< ENDHTMLSecond, Maybe it's a copy/paste issue, but you should use regular single or double quotes in php for strings, not backticks.
All 4 Replies
bigjoke 0 Light Poster
use code button please... i doubt you will get any replies considering the format of your post. good day
oluwafisayo 0 Newbie Poster
< ?php // take in the id of a director and return his/her full name function get_director($director_id) { global $db; $query = ‘SELECT people_fullname FROM people WHERE people_id = ‘ . $director_id; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); extract($row); return $people_fullname; } // take in the id of a lead actor and return his/her full name function get_leadactor($leadactor_id) { global $db; $query = ‘SELECT people_fullname FROM people WHERE people_id = ‘ . $leadactor_id; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); extract($row); return $people_fullname; } // take in the id of a movie type and return the meaningful textual // description function get_movietype($type_id) { global $db; $query = ‘SELECT movietype_label FROM movietype WHERE movietype_id = ‘ . $type_id; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); extract($row); return $movietype_label; } // function to calculate if a movie made a profit, loss or just broke even function calculate_differences($takings, $cost) { $difference = $takings - $cost; if ($difference < 0) { $color = ‘red’; $difference = ‘$’ . abs($difference) . ‘ million’; } elseif ($difference > 0) { $color =’green’; $difference = ‘$’ . $difference . ‘ million’; } else { $color = ‘blue’; $difference = ‘broke even’; } return ‘ < span style=”color:’ . $color . ‘;” > ’ . $difference . ‘ < /span > ’; } //connect to MySQL $db = mysql_connect(‘localhost’, ‘bp6am’, ‘bp6ampass’) or die (‘Unable to connect. Check your connection parameters.’); mysql_select_db(‘moviesite’, $db) or die(mysql_error($db)); // retrieve information $query = ‘SELECT movie_name, movie_year, movie_director, movie_leadactor, movie_type, movie_running_time, movie_cost, movie_takings FROM movie WHERE movie_id = ‘ . $_GET[‘movie_id’]; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); $movie_name = $row[‘movie_name’]; $movie_director = get_director($row[‘movie_director’]); $movie_leadactor = get_leadactor($row[‘movie_leadactor’]); $movie_year = $row[‘movie_year’]; $movie_running_time = $row[‘movie_running_time’] .’ mins’; $movie_takings = $row[‘movie_takings’] . ‘ million’; $movie_cost = $row[‘movie_cost’] . ‘ million’; $movie_health = calculate_differences($row[‘movie_takings’], $row[‘movie_cost’]); // display the information echo < < < ENDHTML < html > < head > < title > Details and Reviews for: $movie_name < /title > < /head > < body > < div style=”text-align: center;” > < h2 > $movie_name < /h2 > < h3 > < em > Details < /em > < /h3 > < table cellpadding=”2” cellspacing=”2” style=”width: 70%; margin-left: auto; margin-right: auto;” > < tr > < td > < strong > Title < /strong > < /strong > < /td > < td > $movie_name < /td > < td > < strong > Release Year < /strong > < /strong > < /td > < td > $movie_year < /td > < /tr > < tr > < td > < strong > Movie Director < /strong > < /td > < td > $movie_director < /td > < td > < strong > Cost < /strong > < /td > < td > $$movie_cost < td/ > < /tr > < tr > < td > < strong > Lead Actor < /strong > < /td > < td > $movie_leadactor < /td > < td > < strong > Takings < /strong > < /td > < td > $$movie_takings < td/ > < /tr > < tr > < td > < strong > Running Time < /strong > < /td > < td > $movie_running_time < /td > < td > < strong > Health < /strong > < /td > < td > $movie_health < td/ > < /tr > < /table > < /div > < /body > < /html > ENDHTML; ? >
Thanks. I am about to apply the code. At last I could continue studying php
pritaeas 2,276 Most Valuable Poster Moderator Featured Poster
echo < < < ENDHTML should be echo <<< ENDHTML Second, Maybe it's a copy/paste issue, but you should use regular single or double quotes in php for strings, not backticks.
SHARMA1 0 Newbie Poster
I Think you are not weak in php but there is very little problem of commas and place so you need to settle it.
Edited by Ezzaral because: Snipped "fake sig" link. Please restrict such links to your site-wide user signature, which can be edited from the user control panel.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.