【问题标题】:link syntax error using php [closed]使用php的链接语法错误[关闭]
【发布时间】:2013-05-06 13:32:46
【问题描述】:

我在 php 中编写了一个基本循环,可以满足我的需要,但现在我也尝试添加一个链接,但无法正确获取语法,并且我发现语法对我不起作用的示例并不断获取错误。如果有人能告诉我我哪里出错了,那就太棒了。提前感谢您是否能够提供帮助!

引发错误的代码是

<a href=\"addcomment.php?id="'. $row['postid'] .'\">' "Add Comment" '</a>");

完整的代码是。

<?php
    include("connect.php"); //connect to database
    //create query
    $get_messages_query = $db->prepare("
        SELECT * FROM `blogposts`
        ORDER BY `postid` DESC 
        LIMIT 5
        ");
    //Homepage should have last 5 blog posts this will take the //last 5 entered into the database and put them into an //array

    $get_messages_query->execute();
    //executes query above

    while($row = $get_messages_query->fetch())
    {
        $blog_post_history .=
        '<div class="post" id="post">
            <h1>'. $row['title'] .' </h1>
            <h2>' . $row['author'] . '</h2>
            <p>'. $row['content'] . '</p>
            <a href=\"addcomment.php?id="'. $row['postid'] .'\">' "Add Comment" '</a>");

        </div>';
    }

    // while loop that takes info from db query and puts the //information in its own div with title andauthor having a //unique heading for css as well as a p for the content of //the blog. This loop puts the information in //$blog_post_history which is called upon in the div code 
    //below
?>

【问题讨论】:

  • PDO 与任何链接或 HTML 完全无关。

标签: php mysql pdo href


【解决方案1】:

这里的引号有问题

$blog_post_history .=
    '<div class="post" id="post">
        <h1>'. $row['title'] .' </h1>
        <h2>' . $row['author'] . '</h2>
        <p>'. $row['content'] . '</p>
        <a href="addcomment.php?id='. $row['postid'] .'">Add Comment</a>
    </div>';

【讨论】:

    【解决方案2】:
    while($row = $get_messages_query->fetch())
    {
        $blog_post_history .=
        '<div class="post" id="post">
            <h1>'. $row['title'] .' </h1>
            <h2>' . $row['author'] . '</h2>
            <p>'. $row['content'] . '</p>
            <a href="addcomment.php?id='. $row['postid'] .'"> Add Comment </a>
        </div>';
    }
    

    【讨论】:

      猜你喜欢
      • 2015-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 2022-06-18
      • 2018-08-04
      • 1970-01-01
      相关资源
      最近更新 更多