2017-08-13 23:16
浏览 16


Im not sure whats going wrong with this code. I have a paragraph stored in the database under content, but for some reason I can't get it to display. Any help would be greatly appreciated, I'm a newer developer and welcome any feedback.

require_once('db_connection.php'); //connection credentials

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

$sql = "SELECT content FROM content";
$result = mysqli_query($conn, $sql);

while($row = mysqli_fetch_row($result)) { 
    echo $row;


图片转代码服务由CSDN问答提供 功能建议

我不确定这段代码出了什么问题。 我有一个段落存储在数据库中的内容,但由于某种原因我无法显示它。 任何帮助将不胜感激,我是一个新的开发人员,欢迎任何反馈。

require_once('db_connection.php');  //连接凭证
 $ conn = new mysqli($ servername,$ username,$ password,$ dbname); 
 $ sql =“SELECT content FROM content”; 
 $  result = mysqli_query($ conn,$ sql); 
while($ row = mysqli_fetch_row($ result)){
 echo $ row; 
mysqli_close($ conn); 
?&gt; \  n   
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongmopu6734 2017-08-13 23:20

    echo $row; you're missing the column's object's array itself that you want to echo.

    What you want is echo $row[0];

    However, both column and table name are the same, so make sure that that is indeed correct.

    As per the manual:

    Example pulled from the manual:

    $query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";
    if ($result = mysqli_query($link, $query)) {
        /* fetch associative array */
        while ($row = mysqli_fetch_row($result)) {
            printf ("%s (%s)
    ", $row[0], $row[1]);
        /* free result set */

    If the above failed, then that could mean that your query may have failed and you need to check for errors on the query, using mysqli_error($conn).


    Same thing goes for the connection.


    Example from the manual:

    $link = mysqli_connect("", "my_user", "my_password", "my_db");
    if (!$link) {
        echo "Error: Unable to connect to MySQL." . PHP_EOL;
        echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
        echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
    echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
    解决 无用
    打赏 举报

相关推荐 更多相似问题