I have a 'video' page that is passed a variable by the URL (video.php?id=VALUE
). This id
value is used throughout the page to pull in various details about the video - title, a still, year etc.
I want to display a 404/error if an incorrect value (/something not in the database) is entered into the string, and display the page with corresponding values pulled from the database if the value is correct
My code is currently structured like this:
<?php
$video = $_GET['video'];
$videodata = $pdo->prepare("SELECT * FROM video WHERE siteurl = ? LIMIT 1");
$videodata->execute([$video]);
?>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>
<?php
foreach ($videodata as $videodatas) {
echo "{$videodatas['title']}</title>";
echo "<meta property=\"og:title\" content=\"{$videodatas['title']}\"/>"; }?>
<meta name="description" content="Description lives here">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta property="og:url" content="<?php echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];?>" />
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="stylesheet" href="scripts/style.css">
</head>
When this successfully matches it generates the page, listing the correct video title in the <title>
tags and throughout the rest of the page.
However, when I'm testing an incorrect variable in the URL/something that's not in my database the page is spitting out a completely blank page that includes all of the raw HTML in the <title>
tag.
Any help (even in the direction of a tutorial on how to achieve this) would be much appreciated.
EDIT:
I've tried writing some code as a test with the intention to replace the if
and else
statements when I have it working. The code doesn't work at the moment and I'm not sure where I'm going wrong...:
<?php
$video = $_GET['video'];
$videodata = $pdo->prepare("SELECT * FROM video WHERE site url =:siteurl LIMIT 1"); // check db for :siteurl value
$videodata->bindParam(':siteurl', $_GET['video'], PDO::PARAM_STR); // bind site url to $_Get Value...
$videodata->execute([$video]); // execute
if($videodata->rowCount()) { // If videodata [url string] returns data then...
echo '<b>hello world... this entry is there!</b>';
} else {
echo 'NO .... ITS NOT THERE';
}
;
?>