Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从MySQL表列中回显内容_Php_Mysql_Fetch - Fatal编程技术网

Php 如何从MySQL表列中回显内容

Php 如何从MySQL表列中回显内容,php,mysql,fetch,Php,Mysql,Fetch,一段时间以来,我一直试图创建一个管理面板视图,用户可以在其中插入内容,然后发布到网站上。wordpress的一个小版本,目前主要用于私人和教育用途。但是,我无法让它发布从adminpanel视图发送到数据库的内容。它根本不会显示任何东西,这让我觉得我做错了什么 这就是我得到的:连接 <?php session_start(); $adress = 'Host adress goes here'; $dbusername = 'Database username goes here'

一段时间以来,我一直试图创建一个管理面板视图,用户可以在其中插入内容,然后发布到网站上。wordpress的一个小版本,目前主要用于私人和教育用途。但是,我无法让它发布从adminpanel视图发送到数据库的内容。它根本不会显示任何东西,这让我觉得我做错了什么

这就是我得到的:连接

   <?php
session_start();

$adress = 'Host adress goes here';
$dbusername = 'Database username goes here';
$dbpassword = 'Database password goes here';

$anslutning = mysqli_connect($host, $dbusername, $dbpassword);
if (!$anslutning) die ("<br /><b>Can't connect to server</b>");

$anslutning->select_db('Database name goes here') or die ("Could not connect to database");

    ?>
还有我目前无法使用的代码

<p class="welcometext">
    <?php

        $getContentQuery = "SELECT content FROM tblPages";

        if ($getContent = $anslutning->prepare($getContentQuery)) {



        $getContent->execute();
        $result = $anslutning->query($getContentQuery);

        while ($rows = mysql_fetch_array($result)) {

            echo $rows[2];


        }
    }




    ?>
</p>
**编辑:**我刚刚意识到它不会呼应if语句中的任何内容,因此作为一名PHP新手,我不确定它是否应该这样做,或者这就是为什么“while”不起作用


EDIT2:所以我得到了我的答案并给它开了罚单。但是,我需要补充一些东西。虽然我写的从一开始就是错误的,但是删除所有早期的PHP代码似乎可以解决问题,让故障排除开始吧!。我感谢所有人的帮助和时间,只要我能找出是什么打破了它,问题就解决了。

你在回$post,它似乎不存在。回显$rows

您的数据库连接在哪里???也许你正在混合mysql和mysqli!!你说的“准备”是什么意思?但我想你的意思是query@Saty我在上面写了代码,我在代码的上面有一个连接。它可以与其他PHP代码一起使用,所以我对此表示怀疑。我同意@SuperDJ。看起来你把mysql和PDO搞混了,完全错过了这一行。谢谢你指出!然而,这似乎没有帮助。
 if ($getContent = $anslutning->prepare($getContentQuery)) {
     $getContent->execute();
     $content='';
     $getContent->bind_result($content);
     while ($getContent->fetch()) {
        echo $content;
     }
 }