duanhuren5581
2016-04-10 13:44
浏览 100
已采纳

在PHP中使用echo后未显示HTML元素

I am creating a form to update a database and used PHP to query the database and get current values before filling them in as the values already in the input boxes. I used echo to create the HTML elements while inserting the PHP variables however, the elements created aren't being displayed. Here are a couple of the inputs that I tried to make:

// Album Price
echo "<div class=\"row horizontal-center\">" .
"<input type=\"number\" step=\"0.01\" value=\"" . htmlspecialchars($albumPrice) . "\" name=\"albumPrice\"
" .
"</div>";

// Album Genre
echo "<div class=\"row horizontal-center\">" . 
"<input type=\"text\" value=\"" . htmlspecialchars($albumGenre) . "\" name=\"albumGenre\"
" .
"</div>";

Thanks in advance :)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxing4196 2016-04-10 13:47
    已采纳

    Your input elements are not properly closed with a > character. This code should work:

    "<input type=\"number\" step=\"0.01\" value=\"" . htmlspecialchars($albumPrice) . "\" name=\"albumPrice\" />
    " 
    

    Note the /> added in the end of the line. (the / due to <input> not having a closing tag)

    点赞 评论
  • dongzong7467 2016-04-10 13:49

    There's conflicting quotes in your HTML elements. Use single quotes for echo() and double quotes for HTML elements.

    Also, you did not close the <input tag.

    echo '<div class=\"row horizontal-center\">' .
    '<input type=\"number\" step=\"0.01\" value=\"' . htmlspecialchars($albumPrice) . '\" name=\"albumPrice\" />
    ' .
    '</div>';
    
    echo '<div class=\"row horizontal-center\">' . 
    '<input type=\"text\" value=\"' . htmlspecialchars($albumGenre) . '\" name=\"albumGenre\" />
    ' .
    '</div>';
    

    Tip: You should turn on Error Reporting by adding this code to the top of your PHP files which will assist you in finding errors.

    <?php 
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    
    点赞 评论

相关推荐 更多相似问题