0

i Always getting : mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\class\function.php on line 28 please give the suggestion friends

config.php

<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '12345');
define('DB_DATABASE', 'class');
class db_class {

    function db_constractor() {
        $connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die('Oops connection error -> ' . mysql_error());
        mysql_select_db(DB_DATABASE, $connection) or die('Database error -> ' . mysql_error());
    }

}
?>


finction.php


<?php
include_once 'config.php';
class user
{
    public function db_constractor()
    {
        $db = new db_class();
    }
    public function register_user($name, $username, $password, $email)
    {
        $password = md5($passowrd);
        $sql = mysql_query("SELECT uid from users WHERE username ='$username' or email ='$email'");
        $no_rows = mysql_num_rows($sql);
        if($no_rows == 0) 
        {
            $result = mysql_query("INSERT INTO users(username, password, name, email) values('$username', '$password', '$name', 'email')") or die(mysql_error());
            return $result;
        }
        else
        {
            return FALSE;
        }
    }
            public function check_login($emailusername, $password)
            {
                $password = md5($password);
                $result = mysql_query("SELECT uid from users WHERE email = '$emailusername' or username = '$emailusername' and password = '$password'");
                $user_data = mysql_fetch_array($result);
                $no_rows = mysql_num_rows($result);
                if($no_rows == 1)
                {
                    $_SESSION['login'] = TRUE;
                    $_SESSION['uid'] = $user_data['uid'];
                    return TRUE;
                }
                else
                {
                    return FALSE;
                }
            }
            public function get_fullname($uid)
            {
                $result = mysql_query("SELECT name FROM users WHERE uid = $uid");
                $user_name = mysql_fetch_array($result);
                echo $user_name['name'];
            }
            public function get_session()
            {
                return $_SESSION['login'];
            }
            public function user_logout()
            {
                $_SESSION['login'] = FALSE;
                session_destroy();
            }
}
?>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by tiggsy
0

I am not sure, but if your plan was to use db_constractor() as the class constructor, then rename the function to __construct() (in both classes).

The function db_constractor() is never called, so you do not have a database connection causing your query to fail.

Edited by pritaeas

0

It appears that $result contains FALSE, so you should check whether the previous mysql_query is picking anything up.

I find the easiest way to do this is to paste the query into phpMyadmin

Edited by tiggsy

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.