-1

I want to insert the mysql data into the meta tags' content. but when i do it, the server just shows a white page. In my opinion, my code should be working but there's an error that i don't know about.

I am writing my code in the header.php and it is included in all files. But, i only have a file that want to send data to meta tags.
Here's my code.

<?php 
$query = "SELECT * FROM tbl_new WHERE id='$nid'";
$rs = $db->select($query);
while($row = $rs->fetch()){
?>
  <meta property="og:type" content="website">
  <meta property="og:title" content="<?php echo $row['title]; ?>">
  <meta property="og:description" content="<?php echo $row['body']; ?>">
  <meta property="og:url" content="***">
  <meta property="og:image" content="">
  <meta property="og:site_name" content="">
  <meta property="og:app_id" content="012345678910">
<?php } ?>
  • 1
    Perhaps your `$title` and/or `$body` variables contain `"`? If you `view page source` you should be able to see where the error is. – Nick Aug 13 '18 at 05:21
  • I didn't recheck my problem properly and now i am editing it. i want the $row['title'] and $row['body'] in the place of $title and $body. – Lin Myat Aung Aug 13 '18 at 05:28
  • Google PHP white screen. Lots of reasons a white page may happen. If you have a closing php tag ?> at the end of your file , try removing it. Sometimes there are unseen characters after the closing tag and that may cause problem. – anmari Aug 13 '18 at 05:30
  • You have a typo. There is no `$results` variable. It should be `while($row = $rs->fetch())`. Also, to make your code HTML safe, I recommend using `content="= htmlspecialchars($row['title']) ?>"`, etc. This is what @Nick was referring to – Phil Aug 13 '18 at 05:37
  • Ahh! I noticed that and fixed that already in the mean time. but it still didn't work for me. And @anmari i have checked every closing ?> tag but none is missing. – Lin Myat Aung Aug 13 '18 at 05:40
  • Please have a read of [How to get useful error messages in PHP?](https://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php). You will have an error somewhere, a blank / white page just means you're not seeing the error message reported – Phil Aug 13 '18 at 05:40
  • 1
    Thanks @Phil . I have solved the problem – Lin Myat Aung Aug 13 '18 at 08:07

1 Answers1

0

try this code may be it work for you. or any error please let me know .

$query = "SELECT * FROM meta limit 1";
$rs = $conn->prepare($query);
$rs->execute();
while($row = $rs->fetch()){

?>
<!DOCTYPE html>
<html>
<head>
    <meta property="og:type" content="website">
    <meta property="og:title" content="<?php echo $row['title']; ?>">
    <meta property="og:description" content="<?php echo $row['body']; ?>">
    <?php } ?>
    <meta property="og:url" content="***">
    <meta property="og:image" content="">
    <meta property="og:site_name" content="">
    <meta property="og:app_id" content="012345678910">
    <title></title>
 </head>
<body>
    <p>hii</p>
</body>

thanks