0

im new to php mysql, need help. Im unable to show data from mysql database through below codes. It shows a blank page :(. can anyone help me please?. below is my config file and index file codes.

config.php

<?php
class DB {

    protected $db_name = 'drive';
    protected $db_user = 'root';
    protected $db_pass = '';
    protected $db_host = 'localhost';


    public function connect() {
        $connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
        mysql_select_db($this->db_name);
        return true;
    }


class showClass{
    //USER LIST SHOW function
public function showUser($table){

        $query=mysql_query("SELECT * FROM $table WHERE type='user'") or die(mysql_error()); 
        $data=NULL;
        if(mysql_num_rows($query)>0){
            while($rows=mysql_fetch_assoc($query)){
            $data[]=$rows;
            }
            return $data;
        }else{
            echo '<span class="text-info success">No Account Found.</span>';
        exit();
        }

    }

}

index.php

<?php
require_once 'conf/config.php';


$db = new DB();
$db->connect();
$obj_show = new showClass();
?>
<html>
<head>
<title>Drive</title>
</head>
<body>

<table class="table table-bordered table-hover" cellpadding="5">

<tr>
<th scope="col"><b>User ID</b></th>
<th scope="col"><b>Name</b></th>
</tr>


<?php

  $allData=$obj_show->showUser("user");
  foreach($allData as $data){
      extract($data);
        echo <<<show

<tr>
  <td>$id</td>
  <td >$username</td>  
</tr>

show;
  }
  ?>

</table>

</body>

9
  • I'm not sure... But why your first "new" keyword" starts with a capital letter? Plus, did you try to make a var_dump() of $db and $obj_show variables after creating them? Commented Apr 10, 2014 at 5:43
  • no, how can i do a var_dump() ? please tell Commented Apr 10, 2014 at 5:44
  • 1
    if its a blank page, can you check what what is the error display level and add ini_set('display_errors', 1); at the top of your script and check the output again Commented Apr 10, 2014 at 5:47
  • 1
    @opensource-ios i just added ini_set('display_errors', 1); and the page is whoing this Parse error: syntax error, unexpected T_CLASS, expecting T_FUNCTION in C:\wamp\www\connection\conf\config.php on line 20 Commented Apr 10, 2014 at 5:50
  • 1
    make sure mysql extension available in your server. Commented Apr 10, 2014 at 5:56

3 Answers 3

2

As I said in comments already, you're missing } after the end of class DB.

Sign up to request clarification or add additional context in comments.

Comments

2

as @Cruel answer you are missing } at the end of class DB try to change

class DB {

    protected $db_name = 'drive';
    protected $db_user = 'root';
    protected $db_pass = '';
    protected $db_host = 'localhost';


    public function connect() {
        $connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
        mysql_select_db($this->db_name);
        return true;
    }
}

Comments

1

You have a syntax error as shown by your output which got displayed when you added ini_set function

The correct code is as below, you need to add a closing bracket after the class DB

<?php
class DB {

    protected $db_name = 'drive';
    protected $db_user = 'root';
    protected $db_pass = '';
    protected $db_host = 'localhost';


    public function connect() {
        $connection = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
        mysql_select_db($this->db_name);
        return true;
    }

}// MISSING CLOSING BRACKET
class showClass{
    //USER LIST SHOW function
public function showUser($table){

        $query=mysql_query("SELECT * FROM $table WHERE type='user'") or die(mysql_error()); 
        $data=NULL;
        if(mysql_num_rows($query)>0){
            while($rows=mysql_fetch_assoc($query)){
            $data[]=$rows;
            }
            return $data;
        }else{
            echo '<span class="text-info success">No Account Found.</span>';
        exit();
        }

    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.