0

I am trying to print username, password and name from the database but it does not print anything. Please guide me. Thanks.

<?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);
    ?>

Here is my 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"

It is being loaded well but still I do see error messages printed. Thanks.

  • 2
    Please [enable error reporting](http://stackoverflow.com/a/6575502/1438393) to see useful error messages. – Amal Murali Mar 09 '14 at 14:00
  • You are using the syntax for mysqli_fetch_object with mysqli_fetch_array. –  Mar 09 '14 at 14:01
  • Just a quick note - you should be using `htmlspecialchars` to encode output from the database, to ensure that you're not vulnerable to Cross-Site Scripting (XSS) attacks. – Polynomial Mar 09 '14 at 14:01

1 Answers1

3

You need to access $row as this is where the fetched data is, not in the $result!

while ($row = mysqli_fetch_array($result)) {
    if (isSet($_GET['id'])) {
        echo $row['user_id'];//etc.
    }
}
kero
  • 10,647
  • 5
  • 41
  • 51