Dear friends,
Please guide me I want to display data in PHP form from mysql database. my code is below

<?PHP

//connect to database
$username = "root";
$password = "";
$database = "mydatabase";
$server = "127.0.0.1";

$conn= mysqli_connect($server,$username,$password,$database);
       // checkintin connection

       if($conn->connect_error){
                              die("".$conn->connect_error);
        }

             // select data

    $sql = "SELECT * FROM myguests";
    $result=$conn->query($sql);

                               if($result->num_row>0){
                               //output data of each row
                                    while($row=$result->fetch_assco()){
                                          echo "ID:".$row["id"];

                                    }
                                }   
                                    else{

                                    echo "no any record is in table";
                                        }

    $conn->close();                             



?>

what is there problem?

Maybe line 23: while($row=$result->fetch_assco()){...

It should probably be:

while($row=$result->fetch_assoc()){...

assoc stands for associative; this method returns a row in an associative array where field names are keys.

or maybe you can use fetch_array().

 $query = mysql_query(select column from table);

 while($row=mysql_fetch_array($query)){ 
    echo $row['column'];
 }
commented: Gives a mysql answer to a mysqli question... +0

dear Friends,
here is error message....

Notice: Trying to get property of non-object in C:\wamp\www\db\viewdb.php on line 31

and line no 31 is

$result->row_num>0;
Please, guide me...

is actually $result->num_rows>0

Dear Adrian!
yes i used

if($result->num_rows){
                     while($row=$result->fetch_assoc()){

                                               echo "".$row["id"];


                     }

}

but error message is same...plz help me.

Trying to get property of non-object in C:\wamp\www\db\viewdb.php on line 31

and 31 line is
if($result->num_rows>0)

Trying to get property of non-object in C:\wamp\www\db\viewdb.php on line 31

That means that $result is false because your query failed.

yes priteas, no any record shown .... but why?My query seems correct......

$sql="SELECT * FROM mydatabase";

plz guide me.

Please, put all the (corrected) code...

WOOOOOOOOOOWW... That was sooooo noob from my part...

The problem with your script is that you connect "procedurally" and then work with mysqli "objectually". Mysqli has dual interfaces: a procedural one and an object-oriented one. You connected to the database using the procedural interface, but after that you worked with a $conn which was not an object (I sure hope that you understand what I mean...).

Instead of connecting like this:
$conn= mysqli_connect($server,$username,$password,$database);

..., you should connect like this:
$conn = new mysqli($server,$username,$password,$database);

dear Adrian here is all my correct code..

$username = "root";
$password = "";
$database = "addressbook";
$server = "127.0.0.1";

$conn= new mysqli($server,$username,$password,$database);
       // checkinting connection

       if($conn->connect_error){
                        die("connection failed:".$conn->connect_error);
        }
       //select data from database

        $sql="SELECT id,firstname FROM myguests";
        $result=$conn->query($sql);


     **if($result->num_rows>0){** //in this line is shown error of non object //property

           While($row=$result->fetch_assoc()){
                    echo "ID: ".$row["id"];        

           }
         }
         else{
              echo"record 0";
              }
              $conn->close();
?>

is there anything wrong? But same message is yet...:(((((((

On line 20 add:

if (!$result)
    die($conn->error);

Thx Priaeas..I got it thank you..It soved..

It would be nice for you to tell us where the problem was...

if(!$result){
die($conn->error);}

here is correct code solution of my problem..anyways thank u for alls.

Dear Friends,
Please , check this code for registration form PHP ,data is not entered in database what is problem?

 $sql="SELECT L1 FROM login1 WHERE L1='$uname'";
                     $result=$conn->query($sql);

                     if ($result->num_rows==1){
                       echo("user name is not available ...");

                     }
                     else{
                              $query="INSERT INTO login1(L1,L2) VALUES ('$uname',$pword)";
                              if($conn->query($query)==true){
                              echo ("data has entered sucessfully...");
                              }
                              else{
                                echo("data is not entered due to any problem");
                              }

                     //echo("User name is available..");

                     }

after exicuted got
message "data is not entered due to any problem"

yes i got error there was not single qout in '$pword'
thanks allot..