用PHP打印变量

时间:2014-03-09 13:57:57

标签: 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"

它正在加载但我仍然看到打印出错误消息。感谢。

1 个答案:

答案 0 :(得分:3)

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

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