Mysql Errors - mysql_num_rows.

Status
Not open for further replies.

Roon

Member
Mar 31, 2013
60
9
Okay, so after about 20 minutes of trying to get a mysql_query to work I've decided to ask you guys. :)
Basically, I have a class called amlinks and it is this...
PHP:
    public function amlinker()    {
            $aretheyMOD = mysql_query("SELECT * FROM `users` WHERE `Username` = 'Roon' AND `isMod` = '1'");
            $aretheyADMIN = mysql_query("SELECT * FROM `users` WHERE `Username` = 'Roon' AND `isAdmin` = '1'");
            $rows_MOD = mysql_num_rows($aretheyMOD);           --- LINE 61 ---
            $rows_ADMIN = mysql_num_rows($aretheyADMIN);      --- LINE 62 ---
 
            if($rows_ADMIN = 1){
            echo "SUP ADMIN";   
            } else {
            echo "NOT ADMIN" . mysql_error();   
            }               
        }
This is giving me the errors "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\Xampp\htdocs\ForumZer\inc\inc.main.php on line 61

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\Xampp\htdocs\ForumZer\inc\inc.main.php on line 62"
If you need any more of my coding to help me, I'll be happy to send it.
Thanks in advance.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
1. does the table 'users' exist?
2. does the column 'Username' exist?
3. does the column 'isMod' exist?
4. does the column 'isAdmin' exist?

Bare in mind, the table names and column names are case-sensitive so 'isMod' is not the same as 'ismod' etc.
 

Roon

Member
Mar 31, 2013
60
9
Yes they do,
a26d8ff847fdfe25469f6c16356ec724.png

Also,
012018889841a052ed637d46bfe85869.png
 

Roon

Member
Mar 31, 2013
60
9
Excuse how messy it is, I'm new to this stuff-ish not really.
PHP:
<?php
class forum {
    public function connect() {
        $con = mysql_connect( ;) );
        mysql_select_db('forum', $con);
    }
    public function login() {
        $Username = $_POST['Username'];
        $Password = $_POST['Password'];
        $fetch_Username = mysql_query("SELECT * FROM `users` WHERE `Username` = '$Username'");
        $fetch_Password = mysql_query("SELECT * FROM `users` WHERE `Password` = '$Password'");
        $row_U = mysql_num_rows($fetch_Username);
        $row_P = mysql_num_rows($fetch_Password);
 
        if($row_U && $row_P == 1){
            session_start();
            $_SESSION['Username'] = $Username;
            header('Location: ../index.php');
        }
        else {
            header('Location: ../loginfailed.php');       
        }
}
    public function loginouty() {
        session_start();
        if(!isset($_SESSION['Username'])) {
        echo "<form style=\"display: inline-block; position: absolute; right: -1050px;\" action=\"inc/inc.main.php\" method=\"POST\" name=\"Form-Login\">
                      <input style=\"margin-top:5px;\" type=\"text\" id=\"loginname\" class=\"input-small\" placeholder=\"Username\" name=\"Username\">
                        <input style=\"margin-top:5px;\" type=\"password\" id=\"loginpass\" class=\"input-small\" placeholder=\"Password\" name=\"Password\">
                        <input type=\"button\" id=\"loginsub\" class=\"btn btn-inverse\" value=\"Login\" name=\"Login-Button\">
                    <input type=\"submit\" id=\"realloginsub\" class=\"btn btn-inverse\" value=\"Login\" name=\"Login-Form-Button\">
                </form>";       
        }   
        else {
        $Username = $_SESSION['Username'];
        echo "<form action=\"logout.php\" style=\"display: inline-block; position: absolute; right: -1050px;\">
                    <input type=\"submit\" class=\"btn btn-danger\" value=\"Logout\">
                </form>";
        echo "    <div style=\"margin-top: 3.5px; display: inline-block; position: absolute; right: -965px;\" class=\"btn-group\">
    <button class=\"btn\">$Username</button>
    <button class=\"btn dropdown-toggle\" data-toggle=\"dropdown\">
    <span class=\"caret\"></span>
    </button>
    <ul class=\"dropdown-menu\">
    <li class=\"divider\"></li>
    <li><a style=\"text-align: center;\" href=\"account.php\">My Account</a></li>
    <li><a style=\"text-align: center;\" href=\"settings.php\">Settings</a></li>
    <li class=\"divider\"></li>
    <li><a style=\"text-align: center;\" href=\"#\">New Status</a></li>
    <li><a style=\"text-align: center;\" href=\"#\">New Avatar</a></li>
    <li class=\"divider\"></li>
    </ul>
    </div>";                   
        }
}
}
    class amlinks {
        public function amlinker()    {
            $aretheyMOD = mysql_query("SELECT * FROM `users` WHERE `Username` = 'Roon' AND `isMod` = '1'");
            $aretheyADMIN = mysql_query("SELECT * FROM `users` WHERE `Username` = 'Roon' AND `isAdmin` = '1'");
            $rows_MOD = mysql_num_rows($aretheyMOD);
            $rows_ADMIN = mysql_num_rows($aretheyADMIN);
 
            if($rows_ADMIN = 1){
            echo "SUP ADMIN";   
            } else {
            echo "NOT ADMIN" . mysql_error();   
            }               
        }   
    }
 
    $ams = new amlinks;
    $ams->amlinker();
    $forum = new forum;
    $forum->connect();
?>
<?php   
    if(isset($_POST['Login-Form-Button'])) {
        $forum->login();
}
?>
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
I noticed you have this:

PHP:
$ams = new amlinks;
$ams->amlinker();
$forum = new forum;
$forum->connect();

Try swapping it for this:

PHP:
$forum = new forum;
$forum->connect();
$ams = new amlinks;
$ams->amlinker();

Not sure if that will work, but by theory you're trying to run an MySQL query before you have connected to the database. ($forum->connect());.
 
Status
Not open for further replies.

Users who are viewing this thread

Top