输出数据库mysqli的内容

Hi I know this is a little general but its something I cant seem to work out by reading online.

Im trying to connnect to a database using php / mysqli using a wamp server and a database which is local host on php admin.

No matter what I try i keep getting the error Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given when i try to output the contents of the database.

the code im using is:

if (isset($_POST["submit"]))
{
    $con = mysqli_connect("localhost");
    if ($con == true)
    {
        echo "Database connection established";
    }
    else 
    {
        die("Unable to connect to database");
    }

    $result = mysqli_query($con,"SELECT *");

    while($row = mysqli_fetch_array($result))
    {
        echo $row['login'];
    }
}

The best way to do this is to go and check these links out. http://php.net/manual/en/index.php

I will be good if you have a look at the standard mysqli_connect here I will dont seem to see where you have selected any data base before attempting to dump it contents.

<?php
//set up basic connection :
$con = mysqli_connect("host","user","passw","db") or die("Error " . mysqli_error($con));
?>

Following this basic standard will also help you know where prob is.

you have to select from table . or mysqli dont know what table are you selecting from.

change this

  $result = mysqli_query($con,"SELECT *");

to

  $result = mysqli_query($con,"SELECT * FROM table_name ");
  • table_name is the name of your table

and your connection is tottally wrong.

use this

 $con = mysqli_connect("hostname","username","password","database_name");

you have to learn here how to connect and use mysqli