错误显示,而提取日志:图像从数据库在主页上的php


Error shown while extracting og:image from database on homepage in php?

我已经从mysql数据库中提取了要在facebook共享上看到的og图像。下面的代码已经工作,但唯一的问题是,它显示了一个错误:" />在我的主页的顶部。

我如何从我的主页上删除这个" />标志?这段代码我写错了吗?

任何对我的问题的指导都是非常感谢的。

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <?php
    $fetch_sql = "SELECT fld_news_pictures,  fld_news_name, fld_news_details FROM tbl_news ";
    $fetch_result= mysql_query($fetch_sql) or die(mysql_error()); 
    while($fetch_row=mysql_fetch_array($fetch_result))
    {
    $fld_news_name = $fetch_row['fld_news_name'];
    $fld_news_pictures = $fetch_row['fld_news_pictures'];
    $fld_news_details = $fetch_row['fld_news_details'];
    ?>
    <meta property="og:title" content="<?php echo $fld_news_name; }?>" />
    <meta property="og:image" content="http://mysite/images/<?php echo $fld_news_pictures; ?>" />
    <meta property="og:description" content="<?php echo $fld_news_details } ?>" />

编辑:你有一个额外的括号在你的og:title标签}?>应该被删除。使用错误报告应该抛出一个解析错误。

  • 还要确保文件有.php扩展名。

顺便说一下,mysql_函数已被弃用,并将在PHP 7.0中删除

习惯在预处理语句中使用mysqli_或PDO。

另外,它是未知的,你正在使用MySQL API连接。根据你的帖子,它应该是mysql_,而不是mysqli_或PDO。这些不同的api不能混用。

    然而,你现在应该使用mysqli_或PDO,然后将你的整个代码转换为最新的API。

重写:(放置在你的文档的<head></head>)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
$fetch_sql = "SELECT fld_news_pictures,  fld_news_name, fld_news_details FROM tbl_news ";
$fetch_result= mysql_query($fetch_sql) or die(mysql_error()); 
while($fetch_row=mysql_fetch_array($fetch_result))
{
$fld_news_name = $fetch_row['fld_news_name'];
$fld_news_pictures = $fetch_row['fld_news_pictures'];
$fld_news_details = $fetch_row['fld_news_details'];
?>
<meta property="og:title" content="<?php echo $fld_news_name; ?>" />
<meta property="og:image" content="http://mysite/images/<?php echo $fld_news_pictures; ?>" />
<meta property="og:description" content="<?php echo $fld_news_details; ?>" /> <?php } ?>