0

Keep getting these errors:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Projeto\all.php on line 71

Notice: Use of undefined constant total2 - assumed 'total2' in C:\xampp\htdocs\Projeto\all.php on line 72

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Projeto\all.php on line 124

Notice: Undefined variable: connect in C:\xampp\htdocs\Projeto\all.php on line 174

Warning: mysql_close() expects parameter 1 to be resource, null given in C:\xampp\htdocs\Projeto\all.php on line 174
------------------------------------------------------------------------------------------------
Really need help!
Here's the whole file!(doesnt have html, head, or body, cus i separated the files to make it easier for css.)

all.php:

<h2>List of all the users</h2>
<div class="center_float">

    <?php
    require 'conf/connection.php';

    $number = 5;

    if (isset($_GET['order'])) {
        $mode = $_GET['mode'];
        $order = $_GET['order'];
    } else {
        $mode = "UP";
        $order = "name";
    }

    function mode($order, $mode, $current) {
        if ($order == $current) {
            if ($mode == "UP") {
                $mode = "DOWN";
            } else {
                $mode = "UP";
            }
        } else {
            $mode = "UP";
        }
        return $mode;
    }

    function mode_complete($order, $mode, $current) {
        if ($order == $current) {
            if ($mode == "UP") {
                $mode_complete = "Up";
            } else {
                $mode_complete = "Down";
            }
        } else {
            $mode_complete = "Up";
        }
        return $mode_complete;
    }

    function arrow($order, $mode, $current) {
        if ($order == $current) {
            $img_id = "ord_" . $order;
            echo "<img src='img/" . $mode . ".png' id='" . $img_id . "'>";
        }
    }

    function mouse($order, $mode, $current) {
        if ($order == $current) {
            $img_id = "ord_" . $order;
            $mode_over = ($mode == "UP") ? "DOWN" : "UP";
            echo "onmouseover='order(\"" . $img_id . "\",\"" . $mode_over . "\")' ";
            $mode_out = ($mode == "UP") ? "UP" : "DOWN";
            echo "onmouseout='order(\"" . $img_id . "\",\"" . $mode_out . "\")' ";
        }
    }

    if (isset($_GET['page'])) {
        $page = (int) $_GET['page'];
        $home = ($page - 1) * $number;
    } else {
        $page = 1;
        $home = 0;
    }

    $total_selection = mysql_query("SELECT * FROM users");
    $total = mysql_num_rows($total_selection);
    $r = mysql_query("SELECT * FROM users ORDER BY $order $mode LIMIT $home, $number");
    $total2 = mysql_num_rows($r);
    $final_number2 = $home + $total2;
    $value = ceil($total / $number);
    $start_number = $home + 1;
    $final_number = $home + $number;

    if ($total == 0) {
        echo "<p>No users registered.</p>";
    } elseif ($total == 1) {
        echo "<p>There's only <b>1</b> user registered.</p>";
    }

    if ($total > 1) {
        if ($value > 1) {
            if ($total2 < $number) {
                if ($start_number == $final_number2) {
                    echo "<p>Showing <b>1</b> result from the total of <b>$total</b> separated in <b>$value</b> page.</p>";
                } else {
                    echo "<p>Showing <b>$start_number</b> - <b>$final_number2</b> results from the total of <b>$total</b> separated in <b>$value</b> pages.</p>";
                }
            } else {
                echo "<p>Showing <b>$start_number</b> - <b>$final_number</b> results from the total of <b>$total</b> separated in <b>$value</b> pages.</p>";
            }
        } else {
            echo "<p>Showing <b>$total</b> results in <b>1</b> page.</p>";
        }
    }

    if ($total) {
        if ($page >= 1 && $page <= $value) {
            ?>

            <br>
            <table class="tab_all">

                <tr>
                    <th width="30"><a href="?p=all&page=<?php echo $page ?>&order=id&mode=<?php echo mode($order, $mode, 'id') ?>" title="Order per ID <?php echo mode_complete($order, $mode, 'id') ?>" <?php echo mouse($order, $mode, 'id') ?> class="lth">ID <?php arrow($order, $mode, 'id') ?></a></th>
                    <th width="220"><a href="?p=all&page=<?php echo $page ?>&order=name&mode=<?php echo mode($order, $mode, 'name') ?>" title="Order per Name <?php echo mode_complete($order, $mode, 'name') ?>" <?php echo mouse($order, $mode, 'name') ?> class="lth">Name <?php arrow($order, $mode, 'name') ?></a></th>
                    <th width="70"><a href="?p=all&page=<?php echo $page ?>&order=username&mode=<?php echo mode($order, $mode, 'username') ?>" title="Order per Username <?php echo mode_complete($order, $mode, 'username') ?>" <?php echo mouse($order, $mode, 'username') ?> class="lth">Username <?php arrow($order, $mode, 'username') ?></th>
                    <th width="70"><a href="?p=all&page=<?php echo $page ?>&order=password&mode=<?php echo mode($order, $mode, 'password') ?>" title="Order per Password <?php echo mode_complete($order, $mode, 'password') ?>" <?php echo mouse($order, $mode, 'password') ?> class="lth">Password <?php arrow($order, $mode, 'password') ?></th>
                    <th width="170"><a href="?p=all&page=<?php echo $page ?>&order=email&mode=<?php echo mode($order, $mode, 'email') ?>" title="Order per E-mail <?php echo mode_complete($order, $mode, 'email') ?>" <?php echo mouse($order, $mode, 'email') ?> class="lth">E-mail <?php arrow($order, $mode, 'email') ?></th>
                    <th width="80"><a href="?p=all&page=<?php echo $page ?>&order=birth_date&mode=<?php echo mode($order, $mode, 'birth_date') ?>" title="Order per Birth Date <?php echo mode_complete($order, $mode, 'birth_date') ?>" <?php echo mouse($order, $mode, 'birth_date') ?> class="lth">Birth Date <?php arrow($order, $mode, 'birth_date') ?></th>
                    <th width="80"><a href="?p=all&page=<?php echo $page ?>&order=register_date&mode=<?php echo mode($order, $mode, 'register_date') ?>" title="Order per Register Date <?php echo mode_complete($order, $mode, 'register_date') ?>" <?php echo mouse($order, $mode, 'register_date') ?> class="lth">Register Date <?php arrow($order, $mode, 'register_date') ?></th>
                    <th width="50">Edit</th>
                    <th width="50">Delete</th>
                </tr>

                <?php
                $counter = 0;

                while ($info = mysql_fetch_array($r)) {
                    $class = ($counter % 2 == 0) ? 'odd' : 'even';
                    $counter++;

                    $birth_date = explode("-", $info['birth_date']);
                    $birth_date = $birth_date[2] . '-' . $birth_date[1] . '-' . $birth_date[0];

                    $register_date = explode("-", $info['register_date']);
                    $register_date = $register_date[2] . '-' . $register_date[1] . '-' . $register_date[0];

                    echo "<tr class=\"$class\">";
                    echo "<td>" . $info['id'] . "</td>";
                    echo "<td class=\"left\">" . $info['name'] . "</td>";
                    echo "<td>" . $info['username'] . "</td>";
                    echo "<td>" . $info['password'] . "</td>";
                    echo "<td>" . $info['email'] . "</td>";
                    echo "<td>" . $birth_date . "</td>";
                    echo "<td>" . $register_date . "</td>";
                    echo "<td><a href='?p=edit&id=" . $info['id'] . "' title='Edit'><img src='img/edit.png'></a></td>";
                    echo "<td><a href='conf/delete.php?id=" . $info['id'] . "&action=delete' title='Delete'><img src='img/delete.png' onclick='return confirm(\"Are you sure you want to delete " . $info['name'] . "?\")'></a></td>";
                    echo "</tr>";
                }
                ?>
            </table>
            <br>
            <?php
            $previous = $page - 1;
            $next = $page + 1;

            if ($page > 1) {
                echo '<a href="?p=all&page=' . $previous . '" class="paging">« Previous</a>';
            } else {
                echo '<span class="deactivated">« Previous</span>';
            }

            if ($value > 1) {
                for ($i = 1; $i <= $value; $i++) {
                    $class = ($i == $page) ? 'current_paging' : 'paging';
                    echo '<a href="?p=all&page=' . $i . '" class="' . $class . '">' . $i . '</a>';
                }
            }
            if ($page < $value) {
                echo '<a href="?p=all&page=' . $next . '" class="paging">Next »</a>';
            } else {
                echo '<span class="deactivated">Next »</span>';
            }
        } else {
            echo "<p>This page doesn't exist.</p>";
        }
    }
    mysql_close($connect);
    ?>

</div>

Edited by richaell: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by mikulucky
0

The errors are all about your mysql connection, there must be something wrong with the connection in your included file at the top. Plus your using Undefined constants, the errors are telling you whats wrong and where the errors are.

But first sort out the connection problems.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.