SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict moonchild's Avatar
    Join Date
    Nov 2003
    Location
    U$A
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help finding a stupid parse error...

    the php parser says this:

    Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in c:\inetpub\wwwroot\languages\php\class.mysql_lib.1.11.inc.php on line 33

    Line 31-33 is:

    PHP Code:
    class Authenticate extends MySQL {
        
    // Initialize Variables ----------------------------------------------------------------------------------
            
    $this->user
    here is the code, but i don't see where it is getting an error from that line.

    PHP Code:
    <?php

    class Session {
        
    // Function: Session() -----------------------------------------------------------------------------------
            
    function Session() {
                
    session_start();
            }
        
    // Function: Add() ---------------------------------------------------------------------------------------
            
    function Add($var,$val) {
                
    $_SESSION[$var] = $val;
            }
        
    // Function: Remove() ------------------------------------------------------------------------------------
            
    function Remove($var) {
                unset(
    $_SESSION[$var]);
            }
        
    // Function: Exists() ------------------------------------------------------------------------------------
            
    function Exists($var) {
                if(isset(
    $_SESSION[$var])) {
                    return 
    TRUE;
                } else {
                    return 
    FALSE;
                }
            }
        
    // Function: Destroy() -----------------------------------------------------------------------------------
            
    function Destroy() {
                
    $_SESSION = array();
                
    session_destroy();
            }
    }

    class 
    Authenticate extends MySQL {
        
    // Initialize Variables ----------------------------------------------------------------------------------
            
    $this->user;
            
    $this->pswd;
            
    $this->query                =    "SELECT * FROM ab_users WHERE username = '" $this->user;
            
    $this->query               .=    "' AND password = '" $this->pswd "' LIMIT 1";
        
    // Function: Authenticate() ------------------------------------------------------------------------------
            
    function Authenticate($user,$pswd) {
                
    $this->user trim($user);
                
    $this->pswd trim($pswd);
                
    $this->MySQL($this->query);
                if(
    $this->NumRows() == 1) {
                    return 
    TRUE;
                } else {
                    return 
    FALSE;
                }
            }
    }            

    class 
    MySQL {
        
    // Initialize Variables ----------------------------------------------------------------------------------
            // Database Connection
                
    var $conn_server            MYSQL_SERVER;                // Default MySQL server
                
    var $conn_user                MYSQL_USER;                // Default MySQL username
                
    var $conn_pswd                MYSQL_PSWD;                // Default MySQL password
                
    var $conn_dba                MYSQL_DBA;                // Default MySQL database
            // Error Handling
                
    var $error_flag                FALSE;                    // Error Flag
                
    var $error_msg;                                            // mysql_error();
            // Database Handlers
                
    var $dbh;                                                // mysql_connect();
                
    var $dbs;                                                // mysql_select_db();
                
    var $dbc;                                                // mysql_close();
            // Database Functions
                
    var $query;                                                // SQL String
                
    var $result;                                            // mysql_query();
                
    var $numrows;                                            // mysql_num_rows();
                
    var $flush;                                                // mysql_free_result();
                
    var $fetchArray;                                        // mysql_fetch_array();
                
    var $fetchAssoc;                                        // mysql_fetch_assoc();
                
    var $fetchRow;                                            // mysql_fetch_row();
                
    var $fetchObj;                                            // mysql_fetch_obj();
                
    var $createDB;                                            // mysql_create_db();
        // Function: MySQL() -------------------------------------------------------------------------------------
            
    function MySQL($query) {
                
    $this->query trim($query);
                
    $this->conn_server trim($this->conn_server);
                
    $this->conn_user trim($this->conn_user);
                
    $this->conn_pswd trim($this->conn_pswd);
                
    $this->conn_dba trim($this->conn_dba);
                if(empty(
    $this->conn_server) || empty($this->conn_user) || empty($this->conn_dba)) {
                    
    $this->error_flag TRUE;
                    
    $this->Error('');
                    exit;
                } else {
                    
    $this->Connect();
                }
            }
        
    // Function: Create_DB() ---------------------------------------------------------------------------------
            
    function Create_DB($db) {
                
    $this->createDB mysql_create_db($db);
                if(!
    $this->createDB) {
                    
    $this->error_msg mysql_error();
                    
    $this->error_num mysql_errno();
                    
    $this->Error('Create_DB');
                }
            }
        
    // Function: Connect() -----------------------------------------------------------------------------------
            
    function Connect() {
                
    $this->dbh mysql_connect($this->conn_server,$this->conn_user,$this->conn_pswd);
                if(!
    $this->dbh) {
                    
    $this->error_msg mysql_error();
                    
    $this->error_num mysql_errno();
                    
    $this->Error('Connect');
                } else {
                    
    $this->Select_DB();
                }
            }
        
    // Function: Select_DB() ---------------------------------------------------------------------------------
            
    function Select_DB() {
                
    $this->dbs mysql_select_db($this->conn_dba,$this->dbh);
                if(!
    $this->dbs) {
                    
    $this->error_msg mysql_error();
                    
    $this->error_num mysql_errno();
                    
    $this->Error('Select_DB');
                } else {
                    if(!empty(
    $this->query)) {
                        
    $this->Query();
                    }
                }
            }
        
    // Function: Disconnect() --------------------------------------------------------------------------------
            
    function Disconnect() {
                
    $this->dbc mysql_close($this->dbh);
                if(!
    $this->dbc) {
                    
    $this->error_msg mysql_error();
                    
    $this->error_num mysql_errno();
                    
    $this->Error('Disconnect');
                }
            }
        
    // Function: Query() -------------------------------------------------------------------------------------
            
    function Query() {
                
    $this->result mysql_query($this->query);
                if(!
    $this->result) {
                    
    $this->error_msg mysql_error();
                    
    $this->error_num mysql_errno();
                    
    $this->Error('Query');
                }
            }
        
    // Function: NumRows() -----------------------------------------------------------------------------------
            
    function NumRows() {
                
    $this->numrows mysql_num_rows($this->result);
                if(!
    $this->numrows) {
                    
    $this->error_msg mysql_error();
                    
    $this->error_num mysql_errno();
                    
    $this->Error('NumRows');
                } else {
                    return 
    $this->numrows;
                }
            }
        
    // Function: Flush() -------------------------------------------------------------------------------------
            
    function Flush() {
                
    mysql_free_result($this->result);
            }
        
    // Function: FetchArray() --------------------------------------------------------------------------------
            
    function FetchArray() {
                
    $this->fetchArray mysql_fetch_array($this->result);
                return 
    $this->fetchArray;
            }
        
    // Function: FetchAssoc() -------------------------------------------------------------------------------
            
    function FetchAssoc() {
                
    $this->fetchAssoc mysql_fetch_assoc($this->result);
                return 
    $this->fetchAssoc;
            }
        
    // Function: FetchRow() ---------------------------------------------------------------------------------
            
    function FetchRow() {
                
    $this->fetchRow mysql_fetch_row($this->result);
                return 
    $this->fetchRow;
            }
        
    // Function: FetchObj() ---------------------------------------------------------------------------------
            
    function FetchObj() {
                
    $this->fetchObj mysql_fetch_object($this->result);
                return 
    $this->fetchObj;
            }
        
    // Function: Error() -------------------------------------------------------------------------------------
            
    function Error($type) {
                if(
    $this->error_flag) {
                    die(
    '<b>Fatal Error</b>: Could not initialize MySQL class and/or connect to MySQL');
                } else {
                    die(
    '<b>Class Error:</b>: ' $type ' method has failed.<br />(' $this->error_num ') <i>' $this->error_msg '</i>');
                }
            }
    }

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Define MySQL Connection Variables
            
    define('MYSQL_SERVER','localhost');
            
    define('MYSQL_USER','root');
            
    define('MYSQL_PSWD','');
            
    define('MYSQL_DBA','test_db');

        
    // Set Counter Variables
            
    $i 1;
            
    $j 0;
            
    $k 0;

    ?>

    <?php

    if($_POST['_AUTHENTICATE']) {
        
    $auth =& new Authenicate($_POST['user'],$_POST['pswd']);
        if(
    $auth) {
            
    $session = new Session();
            
    $session->Add('user',$_POST['user']);
            
    $session->Add('auth',1);
            echo 
    'You are now logged in!';
        } else {
            echo 
    'Error, username/password did not match!';
        }
    }

    ?>

    <form action="class.mysql_lib.1.11.inc.php" method="post">
    <table>
    <tr>
    <td>Username:</td>
    <td><input type="text" name="user" value="" /></td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type="password" name="pswd" value="" /></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" name="_AUTHENTICATE" value="Log In" /></td>
    </tr>
    </table>
    </form>

    <?php


    /*

        // Create a new MySQL connection
            $db =& new MySQL("SELECT * FROM ab_entries ORDER BY last_name");

        // Populate Table w/ Result
            echo '<table cellpadding="5" cellspacing="2" border="0">';
            echo '<tr>';
            echo '<td bgcolor="#CCCCCC"><b>#</b></td>';
            echo '<td bgcolor="#CCCCCC"><b>Last Name</b></td>';
            echo '<td bgcolor="#CCCCCC"><b>First Name</b></td>';
            echo '<td bgcolor="#CCCCCC"><b>Address</b></td>';
            echo '<td bgcolor="#CCCCCC"><b>City</b></td>';
            echo '<td bgcolor="#CCCCCC"><b>State</b></td>';
            echo '<td bgcolor="#CCCCCC"><b>Email Address</b></td>';
            echo '</tr>';
                while($row = $db->FetchObj()) {
                    echo '<tr>';
                    echo '<td bgcolor="#F9F9F9">' . $i . '</td>';
                    echo '<td bgcolor="#F9F9F9">' . $row->last_name . '</td>';
                    echo '<td bgcolor="#F9F9F9">' . $row->first_name . '</td>';
                    echo '<td bgcolor="#F9F9F9">';
                        if(empty($row->address)) {
                            echo '-';
                        } else {
                            echo $row->address;
                        }
                    echo '</td>';
                    echo '<td bgcolor="#F9F9F9">';
                        if(empty($row->city)) {
                            echo '-';
                        } else {
                            echo $row->city;
                        }
                    echo '</td>';
                    echo '<td bgcolor="#F9F9F9">';
                        if(empty($row->state)) {
                            echo '-';
                        } else {
                            echo $row->state;
                        }
                    echo '</td>';
                    echo '<td bgcolor="#F9F9F9">';
                        if(empty($row->email)) {
                            echo '-';
                        } else {
                            echo '<a href="mailto:' . $row->email . '">' . $row->email . '</a>';
                        }
                    echo '</td>';
                    echo '</tr>';
                    $i++;
                }
                $db->Flush();
            echo '</table>';
        
        // Kill MySQL connection
            $db->Disconnect();

    */

    ?>
    maybe one of you can find the error, because i cannot see it...

  2. #2
    SitePoint Enthusiast Jake1's Avatar
    Join Date
    Oct 2003
    Location
    USA
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class Authenticate extends MySQL 
        
    // Initialize Variables ---------------------------------------------------------------------------------- 
            
    $this->user
            
    $this->pswd
            
    $this->query                =    "SELECT * FROM ab_users WHERE username = '" $this->user
            
    $this->query               .=    "' AND password = '" $this->pswd "' LIMIT 1"
        
    // Function: Authenticate() ------------------------------------------------------------------------------ 
            
    function Authenticate($user,$pswd) { 
                
    $this->user trim($user); 
                
    $this->pswd trim($pswd); 
                
    $this->MySQL($this->query); 
                if(
    $this->NumRows() == 1) { 
                    return 
    TRUE
                } else { 
                    return 
    FALSE
                } 
            } 

    should be

    PHP Code:
    class Authenticate extends MySQL 

            var 
    $user
           var 
    $pswd
            var 
    $query               
           
    var $user
            var 
    $query

            
    function Authenticate($user,$pswd) { 
                
    $this->user trim($user); 
                
    $this->pswd trim($pswd); 
                
    $this->MySQL($this->query); 
                if(
    $this->NumRows() == 1) { 
                    return 
    TRUE
                } else { 
                    return 
    FALSE
                } 
            } 


    You cannot have expressions in class variable declarations, and they are declared as var $variable not $this->var

  3. #3
    SitePoint Addict moonchild's Avatar
    Join Date
    Nov 2003
    Location
    U$A
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jake1
    PHP Code:
    class Authenticate extends MySQL 
        
    // Initialize Variables ---------------------------------------------------------------------------------- 
            
    $this->user
            
    $this->pswd
            
    $this->query                =    "SELECT * FROM ab_users WHERE username = '" $this->user
            
    $this->query               .=    "' AND password = '" $this->pswd "' LIMIT 1"
        
    // Function: Authenticate() ------------------------------------------------------------------------------ 
            
    function Authenticate($user,$pswd) { 
                
    $this->user trim($user); 
                
    $this->pswd trim($pswd); 
                
    $this->MySQL($this->query); 
                if(
    $this->NumRows() == 1) { 
                    return 
    TRUE
                } else { 
                    return 
    FALSE
                } 
            } 

    should be

    PHP Code:
    class Authenticate extends MySQL 

            var 
    $user
           var 
    $pswd
            var 
    $query               
           
    var $user
            var 
    $query

            
    function Authenticate($user,$pswd) { 
                
    $this->user trim($user); 
                
    $this->pswd trim($pswd); 
                
    $this->MySQL($this->query); 
                if(
    $this->NumRows() == 1) { 
                    return 
    TRUE
                } else { 
                    return 
    FALSE
                } 
            } 


    You cannot have expressions in class variable declarations, and they are declared as var $variable not $this->var

    oh crap, i'm getting tired.... i didn't even notice that i did that... d'oh! thanks man!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •