0

Hi so im trying to put all of the useres in a database, table into a html table this is what i have:

<table class="table table-striped">
    <thead>
        <tr>
            <th>UUID</th>
            <th>Full Name</th>
            <th>Email</th>
            <th>Access Key</th>
            <th>Phone Number</th>
            <th>Activated</th>
            <th>Role</th>
        </tr>
    </thead>
    <tbody>

        <?php
        include_once('inc/conf/databaseConnect.php');
        $query = mysql_query("SELECT * FROM list_users ORDER by id");
        while($row = mysql_fetch_array($query)){
            echo "<tr>";
            echo "<td>".$row['uuid']."</td>";
            echo "<td>".$row['firstname'].$rowtwo['lastname']."</td>";
            echo "<td>".$row['email']."</td>";
            echo "<td>".$row['security_key']."</td>";
            echo "<td>".$row['phone_no']."</td>";
            echo "<td>".$row['activated']."</td>";
            echo "<td>".$row['role']."</td>";
            echo "</tr>";
        }
        ?>

    </tbody>
</table>

This dosnt return anything, or any errors. It connects to the database correctly ive checked that its just not retrieving the users.

Image of database structure

databaseConnect.php:

    <?php

//Create Connnection
$sqlLink = mysqli_connect('localhost', 'root', 'classified', 'user_details');

//If Error Connecting
if(!$sqlLink) {
    die('<center><br><h3>Error connecting to servers Database.');
}

?>
13
  • You don't actually check for errors. That may be why you don't see them. Commented Oct 25, 2015 at 15:29
  • 1
    Does that query work on the db directly? Maybe the order by is incorrect and it should be order by uuid? Commented Oct 25, 2015 at 15:31
  • 1
    databaseConnect.php is what we'd like to know is in there. mysql_? mysqli_? PDO? Commented Oct 25, 2015 at 15:35
  • 3
    and have a long hard look at $rowtwo. Commented Oct 25, 2015 at 15:38
  • 1
    Wow @Fred-ii- nice detecting. Josh, you need to use mysqli functions with a mysqli connection. mysql_ functions are for a different, outdated/insecure, driver. Commented Oct 25, 2015 at 15:42

4 Answers 4

2

After seeing your edit because you did not originally show us which connection method you were using; the almighty answer here (least the most important one) is that you can't mix different MySQL APIs.

You need to use the same one from connection to query.

Plus that $rowtwo should be $row as I stated in comments along with my asking about what was inside your databaseConnect.php file.

Get to work with prepared statements also to help protect against an SQL injection.

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

Comments

1

Thanks. I have fixed the issue i updated to using mysqli's methods

<?php
include_once('inc/conf/databaseConnect.php');
$query = $sqlLink->query("SELECT * FROM list_users ORDER by id");
while($row = $query->fetch_array()){
    echo "<tr>";
    echo "<td>".$row['uuid']."</td>";
    echo "<td>".$row['firstname'].$row['lastname']."</td>";
    echo "<td>".$row['email']."</td>";
    echo "<td>".$row['security_key']."</td>";
    echo "<td>".$row['phone_no']."</td>";
    echo "<td>".$row['activated']."</td>";
    echo "<td>".$row['role']."</td>";
    echo "</tr>";
}
?>

Comments

0

At least check for errors:

if ($query = mysql_query("SELECT * FROM list_users ORDER by id");) {
  ...
} else {
  echo '<b>MySQL error:</b><br>' . mysql_error() . '<br />';
}

1 Comment

Its not using the databaseConnect.php file because access denied.
0

You must use mysql_fetch_assoc() instead of mysql_fetch_array or fetch like this mysql_fetch_array($result, MYSQL_ASSOC).

2 Comments

Why can't OP use mysql_fetch_array? This mysql_fetch_array($query) seems valid to me although gives back named and numerical references.
yeah off course it's return both type but, sometime it's changed pointer in array.

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.