i have a problem with php. I write the following code and it returns blank

<?php
                $query = mysql_query("SELECT * FROM users");
                $result = $database->sql_query($query);                         
                while ($dr = $database->sql_fetchrow($result))
                {
                    echo $dr['uid'];
                }
                $database->sql_freeresult($result)

                ?>

i call this
include_once 'includes/db.php';

and on db.php.
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());

Shouldn't line 2 be:

$query = "SELECT * FROM users";

(without the mysql_query part)?

still the same i viewed page source and the code stops before <?php

Member Avatar for iamthwee

DB_DATABASE

should probably be the database name.

`

define('DB_DATABASE', 'wall');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());

`

you mean this? why?

Are you sure your while loop is working then?

Try testing this and check the result:

while(...){
    echo "testing";
    echo $var['id'];
}

And try this too: `mysql_query(...) or die(mysql_error())

What you have is a hidden problem and you need to test every possible thing to indentify a cause.

Member Avatar for iamthwee

DB_USERNAME, DB_PASSWORD

They should also probably be actual values too.

yes they are

define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'Pass');
define('DB_DATABASE', 'simon');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());

no its not working

$query = "SELECT * FROM users";
                $database->sql_query($query);                       
                while ($dr = $database->sql_fetchrow($result))
                {
                    echo 'testing';
                    echo $dr['uid'];
                }
                $database->sql_freeresult($result)

what should i do to identify a hidden problem? tried $query = "SELECT * FROM users" or die(mysql_error()); too

Member Avatar for iamthwee

DB_SERVER

That should be an actual value too, maybe 'localhost' or your domain.

Member Avatar for iamthwee

Also I just noticed your database name in your first post is 'wall' but now it has changed to 'simon' that might also be causing a problem.

yes both are ok. any other hints?

Member Avatar for diafol

My only other hint is I don't know what you are using... I did a quick google search on sql_fetchrow()

I was about to raise the same point. There seems to be some confusion here. A basic mysql connection - WHICH IS DEPRECATED BTW and then the use of a user-defined db object. In addition, there seems to be some reticence with regard to providing the entire code required. Oh - useful descriptive title for the thread too :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.