new problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chrismarsden
Forum Newbie
Posts: 14
Joined: Wed Jul 09, 2008 11:37 am

new problem.

Post by chrismarsden »

hi guys i have a new problem if any one would be oh so kind to help me out again.

i keep gettin the below error and im unsure why.

SQL/DB Error -- [Table 'memberstable.memberstableusers' doesn't exist]
Notice: Trying to get property of non-object in C:\wamp\www\functions.php on line 210
SQL/DB Error -- [Table 'memberstable.memberstableusers' doesn't exist]Notice: Trying to get property of non-object in C:\wamp\www\functions.php on line 210
SQL/DB Error -- [Table 'memberstable.memberstableusers' doesn't exist]
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\lib\connection.php on line 131


connection.php

Code: Select all

<?
 
    // ==================================================================
    //  Author: Justin Vincent (justin@visunet.ie)
    //  Web:    http://www.justinvincent.com
    //  Name:   ezSQL
    //  Desc:   Class to make it very easy to deal with mySQL database connections.
    // ==================================================================
    //  ezSQL Constants
    define("EZSQL_VERSION","1.01");
    define("OBJECT","OBJECT",true);
    define("ARRAY_A","ARRAY_A",true);
    define("ARRAY_N","ARRAY_N",true);
 
    // ==================================================================
    //  The Main Class
    
    class db {
    
        // ==================================================================
        //  DB Constructor - connects to the server and selects a database
        
        function db($dbuser, $dbpassword, $dbname, $dbhost)
        {
    
            $this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword);
            
            if ( ! $this->dbh )
            {
                $this->print_error("<ol><b>Error establishing a database connection!</b><li>Are you sure you have the correct user/password?<li>Are you sure that you have typed the correct hostname?<li>Are you sure that the database server is running?</ol>");
            }
            
                
            $this->select($dbname);
        
        }
        
        // ==================================================================
        //  Select a DB (if another one needs to be selected)
        
        function select($db)
        {
            if ( !@mysql_select_db($db,$this->dbh))
            {
                $this->print_error("<ol><b>Error selecting database <u>$db</u>!</b><li>Are you sure it exists?<li>Are you sure there is a valid database connection?</ol>");
            }
        }
    
        // ==================================================================
        //  Print SQL/DB error.
    
        function print_error($str = "")
        {
            
            if ( !$str ) $str = mysql_error();
            
            // If there is an error then take note of it
            print "<blockquote><font face=arial size=2 color=ff0000>";
            print "<b>SQL/DB Error --</b> ";
            print "[<font color=000077>$str</font>]";
            print "</font></blockquote>";   
        }
    
        // ==================================================================
        //  Basic Query - see docs for more detail
        
        function query($query, $output = OBJECT) 
        {
            
            // Log how the function was called
            $this->func_call = "\$db->query(\"$query\", $output)";      
            
            // Kill this
            $this->last_result = null;
            $this->col_info = null;
    
            // Keep track of the last query for debug..
            $this->last_query = $query;
            
            // Perform the query via std mysql_query function..
            $this->result = mysql_query($query,$this->dbh);
    
            if ( mysql_error() ) 
            {               
                // If there is an error then take note of it..
                $this->print_error();
                return FALSE;   
            }
            else {
    
                // In other words if this was a select statement..
                if ( $this->result )
                {
    
                    // =======================================================
                    // Take note of column info
                    
                    $i=0;
                    while ($i < @mysql_num_fields($this->result))
                    {
                        $this->col_info[$i] = @mysql_fetch_field($this->result);
                        $i++;
                    }
    
                    // =======================================================              
                    // Store Query Results
                    
                    $i=0;
                    while ( $row = @mysql_fetch_object($this->result) )
                    { 
    
                        // Store relults as an objects within main array
                        $this->last_result[$i] = $row;
                        
                        $i++;
                    }
                    
                    @mysql_free_result($this->result);
                }
                
                return TRUE;
    
            }
        }
        
        // ==================================================================
        //
        
        function RecordCount ( $query )
        {
            return mysql_num_rows ( mysql_query ( $query ) );
        }
        
        // ==================================================================
        //
        
        function Mresult ( $query, $a, $b )
        {
            return mysql_result ( mysql_query ( '$query' ), $a, $b );
        }
        
        /**
         * Correctly quotes a string so that all strings are escape coded.
         * 
         * @param string            the string to quote
         * @param [magic_quotes]    if $s is GET/POST var, set to get_magic_quotes_gpc().
         */
 
        function qstr ( $string, $magic_quotes = false )
        {
            if (!$magic_quotes) {
                if (strnatcmp(PHP_VERSION, '4.3.0') >= 0) {
                    return "'" . mysql_real_escape_string($string) . "'";
                }
                $string = str_replace("'", "\\'" , str_replace('\\', '\\\\', str_replace("\0", "\\\0", $string)));
                return  "'" . $string . "'"; 
            }
            return "'" . str_replace('\\"', '"', $string) . "'";
        }
    
        // ==================================================================
        //  Get one variable from the DB - see docs for more detail
        
        function get_var($query=null,$x=0,$y=0)
        {
            
            // Log how the function was called
            $this->func_call = "\$db->get_var(\"$query\",$x,$y)";
            
            // If there is a query then perform it if not then use cached results..
            if ( $query )
            {
                $this->query($query);
            }
            
            // Extract var out of cached results based x,y vals
            if ( $this->last_result[$y] )
            {
                $values = array_values(get_object_vars($this->last_result[$y]));
            }
            
            // If there is a value return it else return null
            return $values[$x]?$values[$x]:null;
        }
    
        // ==================================================================
        //  Get one row from the DB - see docs for more detail
        
        function getRow($query=null,$y=0,$output=OBJECT)
        {
            
            // Log how the function was called
            $this->func_call = "\$db->getRow(\"$query\",$y,$output)";
            
            // If there is a query then perform it if not then use cached results..
            if ( $query )
            {
                $this->query($query);
            }
    
            // If the output is an object then return object using the row offset..
            if ( $output == OBJECT )
            {
                return $this->last_result[$y]?$this->last_result[$y]:null;
            }
            // If the output is an associative array then return row as such..
            elseif ( $output == ARRAY_A )
            {
                return $this->last_result[$y]?get_object_vars($this->last_result[$y]):null; 
            }
            // If the output is an numerical array then return row as such..
            elseif ( $output == ARRAY_N )
            {
                return $this->last_result[$y]?array_values(get_object_vars($this->last_result[$y])):null;
            }
            // If invalid output type was specified..
            else
            {
                $this->print_error(" \$db->getRow(string query,int offset,output type) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N ");  
            }
    
        }
    
        // ==================================================================
        //  Function to get 1 column from the cached result set based in X index
        // se docs for usage and info
    
        function get_col($query=null,$x=0)
        {
            
            // If there is a query then perform it if not then use cached results..
            if ( $query )
            {
                $this->query($query);
            }
            
            // Extract the column values
            for ( $i=0; $i < count($this->last_result); $i++ )
            {
                $new_array[$i] = $this->get_var(null,$x,$i);
            }
            
            return $new_array;
        }
    
        // ==================================================================
        // Return the the query as a result set - see docs for more details
        
        function get_results($query=null, $output = OBJECT)
        {
            
            // Log how the function was called
            $this->func_call = "\$db->get_results(\"$query\", $output)";
            
            // If there is a query then perform it if not then use cached results..
            if ( $query )
            {
                $this->query($query);
            }       
    
            // Send back array of objects. Each row is an object        
            if ( $output == OBJECT )
            {
                return $this->last_result; 
            }
            elseif ( $output == ARRAY_A || $output == ARRAY_N )
            {
                if ( $this->last_result )
                {
                    $i=0;
                    foreach( $this->last_result as $row )
                    {
                        
                        $new_array[$i] = get_object_vars($row);
                        
                        if ( $output == ARRAY_N )
                        {
                            $new_array[$i] = array_values($new_array[$i]);
                        }
    
                        $i++;
                    }
                
                    return $new_array;
                }
                else
                {
                    return null;    
                }
            }
        }
    
    
        // ==================================================================
        // Function to get column meta data info pertaining to the last query
        // see docs for more info and usage
        
        function get_col_info($info_type="name",$col_offset=-1)
        {
    
            if ( $this->col_info )
            {
                if ( $col_offset == -1 )
                {
                    $i=0;
                    foreach($this->col_info as $col )
                    {
                        $new_array[$i] = $col->{$info_type};
                        $i++;
                    }
                    return $new_array;
                }
                else
                {
                    return $this->col_info[$col_offset]->{$info_type};
                }
            
            }
            
        }
    
    
        // ==================================================================
        // Dumps the contents of any input variable to screen in a nicely
        // formatted and easy to understand way - any type: Object, Var or Array
    
        function vardump($mixed)
        {
 
            echo "<blockquote><font color=000090>";
            echo "<pre><font face=arial>";
            
            if ( ! $this->vardump_called )
            {
                echo "<font color=800080><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Variable Dump..</b></font>\n\n";
            }
    
            print_r($mixed);    
            echo "\n\n<b>Last Query:</b> ".($this->last_query?$this->last_query:"NULL")."\n";
            echo "<b>Last Function Call:</b> " . ($this->func_call?$this->func_call:"None")."\n";
            echo "<b>Last Rows Returned:</b> ".count($this->last_result)."\n";
            echo "</font></pre></font></blockquote>";
            echo "\n<hr size=1 noshade color=dddddd>";
            
            $this->vardump_called = true;
 
        }
    
        // Alias for the above function 
        function dumpvars($mixed)
        {
            $this->vardump($mixed); 
        }
    
        // ==================================================================
        // Displays the last query string that was sent to the database & a 
        // table listing results (if there were any). 
        // (abstracted into a seperate file to save server overhead).
        
        function debug()
        {
            
            echo "<blockquote>";
    
            // Only show ezSQL credits once..
            if ( ! $this->debug_called )
            {
                echo "<font color=800080 face=arial size=2><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Debug..</b></font><p>\n";
            }
            echo "<font face=arial size=2 color=000099><b>Query --</b> ";
            echo "[<font color=000000><b>$this->last_query</b></font>]</font><p>";
    
                echo "<font face=arial size=2 color=000099><b>Query Result..</b></font>";
                echo "<blockquote>";
                
            if ( $this->col_info )
            {
                
                // =====================================================
                // Results top rows
                
                echo "<table cellpadding=5 cellspacing=1 bgcolor=555555>";
                echo "<tr bgcolor=eeeeee><td nowrap valign=bottom><font color=555599 face=arial size=2><b>(row)</b></font></td>";
    
    
                for ( $i=0; $i < count($this->col_info); $i++ )
                {
                    echo "<td nowrap align=left valign=top><font size=1 color=555599 face=arial>{$this->col_info[$i]->type} {$this->col_info[$i]->max_length}<br><font size=2><b>{$this->col_info[$i]->name}</b></font></td>";
                }
    
                echo "</tr>";
    
                // ======================================================
                // print main results
    
            if ( $this->last_result )
            {
    
                $i=0;
                foreach ( $this->get_results(null,ARRAY_N) as $one_row )
                {
                    $i++;
                    echo "<tr bgcolor=ffffff><td bgcolor=eeeeee nowrap align=middle><font size=2 color=555599 face=arial>$i</font></td>";
    
                    foreach ( $one_row as $item )
                    {
                        echo "<td nowrap><font face=arial size=2>$item</font></td>";    
                    }
    
                    echo "</tr>";               
                }
    
            } // if last result
            else
            {
                echo "<tr bgcolor=ffffff><td colspan=".(count($this->col_info)+1)."><font face=arial size=2>No Results</font></td></tr>";           
            }
    
            echo "</table>";        
    
            } // if col_info
            else
            {
                echo "<font face=arial size=2>No Results</font>";           
            }
            
            echo "</blockquote></blockquote><hr noshade color=dddddd size=1>";
            
            
            $this->debug_called = true;
        }
    
    
    }
 
?>
chrismarsden
Forum Newbie
Posts: 14
Joined: Wed Jul 09, 2008 11:37 am

Re: new problem.

Post by chrismarsden »

functions.php

Code: Select all

<?php
    // ------------------------------------------------------------------------
    
    /**
     * checkLogin
     *
     * Applies restrictions to visitors based on membership and level access
     * Also handles cookie based "remember me" feature
     *
     * @access  public
     * @param   string
     * @return  bool TRUE/FALSE
     */
 
 
    function checkLogin ( $levels )
    {
        session_start ();
        global $db;
        $kt = split ( ' ', $levels );
        
        if ( ! $_SESSION['logged_in'] ) {
        
            $access = FALSE;
            
            if ( isset ( $_COOKIE['cookie_id'] ) ) {//if we have a cookie
            
                $query =  'SELECT * FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr ( $_COOKIE['cookie_id'] );
 
                if ( $db->RecordCount ( $query ) == 1 ) {//only one user can match that query
                    $row = $db->getRow ( $query );
                    
                    //let's see if we pass the validation, no monkey business
                    if ( $_COOKIE['authenticate'] == md5 ( getIP () . $row->Password . $_SERVER['USER_AGENT'] ) ) {
                        //we set the sessions so we don't repeat this step over and over again
                        $_SESSION['user_id'] = $row->ID;                
                        $_SESSION['logged_in'] = TRUE;
                        
                        //now we check the level access, we might not have the permission
                        if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
                            //we do?! horray!
                            $access = TRUE;
                        }
                    }
                }
            }
        }
        else {          
            $access = FALSE;
            
            if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
                $access = TRUE;
            }
        }
        
        if ( $access == FALSE ) {
            header ( "Location: " . REDIRECT_TO_LOGIN );
        }       
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * get_level_access
     *
     * Returns the level access of a given user
     *
     * @param   string
     * @access  public
     * @return  string
     */
    
    function get_level_access ( $user_id )
    {
        global $db;
        $row = $db->getRow ( 'SELECT Level_access FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr ( $user_id ) );
        return $row->Level_access;
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * logout
     *
     * Handles logouts
     *
     * @param   none
     * @access  public
     */
    
    function logout ()
    {
        //session must be started before anything
        session_start ();
    
        //if we have a valid session
        if ( $_SESSION['logged_in'] == TRUE )
        {   
            //unset the sessions (all of them - array given)
            unset ( $_SESSION ); 
            //destroy what's left
            session_destroy (); 
        }
        
        //It is safest to set the cookies with a date that has already expired.
        if ( isset ( $_COOKIE['cookie_id'] ) && isset ( $_COOKIE['authenticate'] ) ) {
            /**
             * uncomment the following line if you wish to remove all cookies 
             * (don't forget to comment ore delete the following 2 lines if you decide to use clear_cookies)
             */
            //clear_cookies ();
            setcookie ( "cookie_id", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH );
            setcookie ( "authenticate", '', time() - KEEP_LOGGED_IN_FOR, COOKIE_PATH );
        }
        
        //redirect the user to the default "logout" page
        header ( "Location: " . REDIRECT_ON_LOGOUT );
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * clear_cookies
     *
     * Clears the cookies
     * Not used by default but present if needed
     *
     * @param   none
     * @access  public
     */
    
    function clear_cookies ()
    {
        // unset cookies
        if ( isset( $_SERVER['HTTP_COOKIE'] ) ) {
            $cookies = explode ( ';', $_SERVER['HTTP_COOKIE'] );
            //loop through the array of cookies and set them in the past
            foreach ( $cookies as $cookie ) {
                $parts = explode ( '=', $cookie );
                $name = trim ( $parts [ 0 ] );
                setcookie ( $name, '', time() - KEEP_LOGGED_IN_FOR );
                setcookie ( $name, '', time() - KEEP_LOGGED_IN_FOR, '/' );
            }
        }
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * set_login_sessions - sets the login sessions
     *
     * @access  public
     * @param   string
     * @return  none
     */
    
    function set_login_sessions ( $user_id, $password, $remember )
    {
        //start the session
        session_start();
        
        //set the sessions
        $_SESSION['user_id'] = $user_id;
        $_SESSION['logged_in'] = TRUE;
        
        //do we have "remember me"?
        if ( $remember ) {
            setcookie ( "cookie_id", $user_id, time() + KEEP_LOGGED_IN_FOR, COOKIE_PATH );
            setcookie ( "authenticate", md5 ( getIP () . $password . $_SERVER['USER_AGENT'] ), time() + KEEP_LOGGED_IN_FOR, COOKIE_PATH );
        }
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * Validate if email
     *
     * Determines if the passed param is a valid email
     *
     * @access  public
     * @param   string
     * @return  bool
     */
    
    function valid_email ( $str )
    {
        return ( ! preg_match ( "/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", $str ) ) ? FALSE : TRUE;
    }
 
    // ------------------------------------------------------------------------
    
    /**
     * Check unique
     *
     * Performs a check to determine if one parameter is unique in the database
     *
     * @access  public
     * @param   string
     * @param   string
     * @return  bool
     */
 
 
    function checkUnique ( $field, $compared )
    {
        global $db;
 
        $query = $db->getRow ( "SELECT COUNT(*) as total FROM `" . DBPREFIX . "users` WHERE " . $field . " = " . $db->qstr ( $compared ) );
 
        if ( $query->total == 0 ) {
            return TRUE;
        }
        else {
            return FALSE;
        }
    }
 
    // ------------------------------------------------------------------------
    
    /**
     * Validate if numeric
     *
     * Validates string against numeric characters
     *
     * @access  public
     * @param   string
     * @return  bool
     */
 
 
    function numeric ( $str )
    {
        return ( ! ereg ( "^[0-9\.]+$", $str ) ) ? FALSE : TRUE;
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * Validate if alfa numeric
     *
     * Validates string against alpha numeric characters
     *
     * @access  public
     * @param   string
     * @return  bool
     */
 
    function alpha_numeric ( $str )
    {
        return ( ! preg_match ( "/^([-a-z0-9])+$/i", $str ) ) ? FALSE : TRUE;
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * Create a Random String
     *
     * Useful for generating passwords or hashes.
     *
     * @access  public
     * @param   string  type of random string.  Options: alunum, numeric, nozero, unique
     * @param   none
     * @return  string
     */
     
     
    function random_string ( $type = 'alnum', $len = 8 )
    {                   
        switch ( $type )
        {
            case 'alnum'    :
            case 'numeric'  :
            case 'nozero'   :
            
                    switch ($type)
                    {
                        case 'alnum'    :   $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                            break;
                        case 'numeric'  :   $pool = '0123456789';
                            break;
                        case 'nozero'   :   $pool = '123456789';
                            break;
                    }
    
                    $str = '';
                    for ( $i=0; $i < $len; $i++ )
                    {
                        $str .= substr ( $pool, mt_rand ( 0, strlen ( $pool ) -1 ), 1 );
                    }
                    return $str;
            break;
            case 'unique' : return md5 ( uniqid ( mt_rand () ) );
            break;
        }
    }
 
    // ------------------------------------------------------------------------
    
    /**
     * Get username - Returns the username of the logged in member based on session ID
     *
     * @access  public
     * @param   string
     * @return  string/bool
     */
     
     
    function get_username ( $id )
    {
        global $db;
        
        $query = "SELECT `Username` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id );
        
        if ( $db->RecordCount ( $query ) == 1 )
        {
            $row = $db->getRow ( $query );
            
            return $row->Username;
        }
        else {
            return FALSE;
        }
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * Is admin - Determines if the logged in member is an admin
     *
     * @access  public
     * @param   string
     * @return  bool
     */
     
    
    function isadmin ( $id )
    {
        global $db;
        
        $query = "SELECT `Level_access` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id );
        
        if ( $db->RecordCount ( $query ) == 1 )
        {
            $row = $db->getRow ( $query );
            
            if ( $row->Level_access == 1 )
            {
                return TRUE;
            }
            else {
                return FALSE;
            }
        }
        else {
            return FALSE;
        }
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * html2txt - converts html to text
     *
     * @access  public
     * @param   string
     * @return  string
     */
     
    function html2txt ( $document )
    {
        $search = array("'<script[^>]*?>.*?</script>'si",   // strip out javascript
                "'<[\/\!]*?[^<>]*?>'si",        // strip out html tags
                "'([\r\n])[\s]+'",          // strip out white space
                "'@<![\s\S]*?–[ \t\n\r]*>@'",
                "'&(quot|#34|#034|#x22);'i",        // replace html entities
                "'&(amp|#38|#038|#x26);'i",     // added hexadecimal values
                "'&(lt|#60|#060|#x3c);'i",
                "'&(gt|#62|#062|#x3e);'i",
                "'&(nbsp|#160|#xa0);'i",
                "'&(iexcl|#161);'i",
                "'&(cent|#162);'i",
                "'&(pound|#163);'i",
                "'&(copy|#169);'i",
                "'&(reg|#174);'i",
                "'&(deg|#176);'i",
                "'&(#39|#039|#x27);'",
                "'&(euro|#8364);'i",            // europe
                "'&a(uml|UML);'",           // german
                "'&o(uml|UML);'",
                "'&u(uml|UML);'",
                "'&A(uml|UML);'",
                "'&O(uml|UML);'",
                "'&U(uml|UML);'",
                "'&szlig;'i",
                );
        $replace = array(   "",
                    "",
                    " ",
                    "\"",
                    "&",
                    "<",
                    ">",
                    " ",
                    chr(161),
                    chr(162),
                    chr(163),
                    chr(169),
                    chr(174),
                    chr(176),
                    chr(39),
                    chr(128),
                    "ä",
                    "ö",
                    "ü",
                    "Ä",
                    "Ö",
                    "Ü",
                    "ß",
                );
 
        $text = preg_replace($search,$replace,$document);
 
        return trim ( $text );
    }
    
    // ------------------------------------------------------------------------
    
    /**
     * send_email - Handles all emailing from one place
     *
     * @access  public
     * @param   string
     * @return  bool TRUE/FALSE
     */
     
    function send_email ( $subject, $to, $body )
    {
        require ( BASE_PATH . "/lib/phpmailer/class.phpmailer.php" );
        
        $mail = new PHPMailer();
        
        //do we use SMTP?
        if ( USE_SMTP ) {
            $mail->IsSMTP();
            $mail->SMTPAuth = true;
            $mail->Host = SMTP_HOST;
            $mail->Port = SMTP_PORT;
            $mail->Password = SMTP_PASS;
            $mail->Username = SMTP_USER;
        }
 
        $mail->From = ADMIN_EMAIL;
        $mail->FromName = DOMAIN_NAME;
        $mail->AddAddress( $to );
        $mail->AddReplyTo ( ADMIN_EMAIL, DOMAIN_NAME );
        $mail->Subject = $subject;
        $mail->Body = $body;
        $mail->WordWrap = 100;
        $mail->IsHTML ( MAIL_IS_HTML );
        $mail->AltBody  =  html2txt ( $body );
 
        if ( ! $mail->Send() ) {
            if ( RUN_ON_DEVELOPMENT ) {
                echo $mail->ErrorInfo;//spit that bug out :P
            }
            return FALSE;
        }
        else {
            return TRUE;
        }
    }
    
    /**
     * ip_first - let's get a clean ip
     *
     * @access  public
     * @param   string
     * @return  string
     */
 
    function ip_first ( $ips ) 
    {
        if ( ( $pos = strpos ( $ips, ',' ) ) != false ) {
            return substr ( $ips, 0, $pos );
        } 
        else {
            return $ips;
        }
    }
    
    /**
     * ip_valid - will try to determine if a given ip is valid or not
     *
     * @access  public
     * @param   string
     * @return  bool
     */
 
    function ip_valid ( $ips )
    {
        if ( isset( $ips ) ) {
            $ip    = ip_first ( $ips );
            $ipnum = ip2long ( $ip );
            if ( $ipnum !== -1 && $ipnum !== false && ( long2ip ( $ipnum ) === $ip ) ) {
                if ( ( $ipnum < 167772160   || $ipnum > 184549375 ) && // Not in 10.0.0.0/8
                ( $ipnum < - 1408237568 || $ipnum > - 1407188993 ) && // Not in 172.16.0.0/12
                ( $ipnum < - 1062731776 || $ipnum > - 1062666241 ) )   // Not in 192.168.0.0/16
                return true;
            }
        }
        return false;
    }
    
    /**
     * getIP - returns the IP of the visitor
     *
     * @access  public
     * @param   none
     * @return  string
     */
 
    function getIP () 
    {
        $check = array(
                'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR',
                'HTTP_FORWARDED', 'HTTP_VIA', 'HTTP_X_COMING_FROM', 'HTTP_COMING_FROM',
                'HTTP_CLIENT_IP'
                );
 
        foreach ( $check as $c ) {
            if ( ip_valid ( &$_SERVER [ $c ] ) ) {
                return ip_first ( $_SERVER [ $c ] );
            }
        }
 
        return $_SERVER['REMOTE_ADDR'];
    }
    
    /**
     * powered_by - let's thank the man for losing nights so I can play with such tools
     *
     * @access  public
     * @param   none
     * @return  string
     */
    
    function powered_by ()
    {
        $out = '';
 
        $out .= '<div align="right" class="powered">' . "\n";
        $out .= '           Powered by ' . "\n";
        $out .= '           <a href="http://www.roscripts.com" title="roscripts - Programming articles, tutorials and scripts" target="_blank">' . "\n";
        $out .= '               roScripts' . "\n";
        $out .= '           </a>' . "\n";
        $out .= '       </div>' . "\n";
        
        return $out;
    }
    
    /**
     * sanitize - a real sanitizer
     *
     * @access  public
     * @param   none
     * @return  string
     */
     
    function sanitize ( $var, $santype = 3 )
    {
        if ( $santype == 1 ) {
            return strip_tags ( $var );
        }
        if ( $santype == 2 ) {
            return htmlentities ( strip_tags ( $var ), ENT_QUOTES, 'UTF-8' );
        }
        if ( $santype == 3 ) {
            if ( ! get_magic_quotes_gpc () ) {
                return addslashes ( htmlentities ( strip_tags ( $var ), ENT_QUOTES, 'UTF-8' ) );
            }
            else {
               return htmlentities ( strip_tags ( $var ), ENT_QUOTES, 'UTF-8' );
            }
        }
    }
?>
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: new problem.

Post by Benjamin »

Did you install the database tables?
chrismarsden
Forum Newbie
Posts: 14
Joined: Wed Jul 09, 2008 11:37 am

Re: new problem.

Post by chrismarsden »

yeah i used the below in an sql query:

Code: Select all

CREATE TABLE `users` (
  `ID` int(11) NOT NULL auto_increment,
  `Username` varchar(255) NOT NULL,
  `Password` varchar(255) NOT NULL,
  `date_registered` int(11) NOT NULL,
  `Temp_pass` varchar(55) default NULL,
  `Temp_pass_active` tinyint(1) NOT NULL default '0',
  `Email` varchar(255) NOT NULL,
  `Active` int(11) NOT NULL default '0',
  `Level_access` int(11) NOT NULL default '2',
  `Random_key` varchar(32) default NULL,
  PRIMARY KEY  (`ID`),
  UNIQUE KEY `Username` (`Username`),
  UNIQUE KEY `Email` (`Email`)
) ENGINE=MyISAM;
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: new problem.

Post by Benjamin »

users != memberstableusers
chrismarsden
Forum Newbie
Posts: 14
Joined: Wed Jul 09, 2008 11:37 am

Re: new problem.

Post by chrismarsden »

sorry dont understand?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: new problem.

Post by Benjamin »

chrismarsden wrote: SQL/DB Error -- [Table 'memberstable.memberstableusers' doesn't exist]
As you can see, somewhere the table name is incorrect in your code or config file.
chrismarsden
Forum Newbie
Posts: 14
Joined: Wed Jul 09, 2008 11:37 am

Re: new problem.

Post by chrismarsden »

ahhhhhhhhhhhhhhhh thanks... i found the problem... i took the dbprefix out and it works fine now... woo hoo
Post Reply