在PHP中打印变量


Printing variable in PHP

我试图从数据库打印用户名,密码和名称,但它不打印任何东西。请引导我。谢谢。

<?php
    $con=mysqli_connect("localhost","xxxxxx","xxxxx","xxxxx");
    // Check connection
    if (mysqli_connect_errno($con))
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    $result = mysqli_query($con,"SELECT * FROM xxxx");
    var_dump($result);
    if (!$result) {
            echo "<p>There was an error</p>";
            echo $mysqli->error;
    }

    while($row = mysqli_fetch_array($result))
      {
            if ((isset($_GET['id']))) 
            {
                echo "id is ".$_GET['id'];
                echo "<br> username is ".$result->user_id;
                echo "<br> password is ".$result->password;
                echo "<br> password is ".$result->name;
            }
        else
            {
                echo "<br> enter id in parameter";  
            }
      }

    mysqli_close($con);
    ?>

这是我的php.ini:

; any text on a line after an unquoted semicolon (;) is ignored
[php] ; section markers (text within square brackets) are also ignored
; Boolean values can be set to either:
;    true, on, yes
; or false, off, no, none
register_globals = off
track_errors = yes
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
; you can enclose strings in double-quotes
include_path = ".:/usr/local/lib/php"
; backslashes are treated the same as any other character
include_path = ".;c:'php'lib"

它正在加载,但我仍然看到错误信息打印。谢谢。

您需要访问$row,因为这是获取的数据所在的位置,而不是$result !

while ($row = mysqli_fetch_array($result)) {
    if (isSet($_GET['id'])) {
        echo $row['user_id'];//etc.
    }
}