Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SQL problem - Parse error: syntax error, unexpected T_VAR

    Hi, I am getting the following error:
    Parse error: syntax error, unexpected T_VARin /home/myweb/public_html/include/db.inc.php on line 216when I try to run the following script:

    Code:
    <?php
    
    
    
    class DB
    
    {
    
        // Connection parameters
    
    
    
    	var $host = 'localhost';
    
        var $user ="username";
    
        var $password ="password";
    
        var $persistent = false;
    
    	var $adminid='admin';
    
    	var $adminipwd='admin';
    
    	
    
    
    
    
    
    
    
    	// Database connection handle
    
        var $conn = NULL;
    
    
    
        // Query result
    
        var $result = false;
    
    
    
    //    function DB($host, $user, $password, $database, $persistent = false)
    
        function DB()
    
        {
    
    
    
    	}
    
    
    
        function open()
    
        {
    
            // Choose the appropriate connect function
    
            if ($this->persistent) {
    
                $func = 'mysql_pconnect';
    
            } else {
    
                $func = 'mysql_connect';
    
            }
    
    
    
            // Connect to the MySQL server
    
            $this->conn = $func($this->host, $this->user, $this->password);
    
            if (!$this->conn) {
    
                return false;
    
            }
    
    
    
            // Select the requested database
    
            if (!@mysql_select_db($this->database, $this->conn)) {
    
                return false;
    
            }
    
    
    
            return true;
    
        }
    
    
    
    
    
        function close()
    
        {
    
            return (@mysql_close($this->conn));
    
        }
    
    
    
        function error()
    
        {
    
            return (mysql_error());
    
        }
    
    
    
        function query($sql = '')
    
        {
    
            $this->result = @mysql_query($sql, $this->conn);
    
    		return ($this->result != false);
    
        }
    
    
    
        function affectedRows()
    
        {
    
            return (@mysql_affected_rows($this->conn));
    
        }
    
    
    
        function numRows()
    
        {
    
            return (@mysql_num_rows($this->result));
    
        }
    
    	function fieldName($field)
    
        {
    
           return (@mysql_field_name($this->result,$field));
    
        }
    
    	 function insertID()
    
        {
    
            return (@mysql_insert_id($this->conn));
    
        }
    
    
    
        function fetchObject()
    
        {
    
            return (@mysql_fetch_object($this->result, MYSQL_ASSOC));
    
        }
    
    
    
        function fetchArray()
    
        {
    
            return (@mysql_fetch_array($this->result, MYSQL_NUM));
    
        }
    
    
    
        function fetchAssoc()
    
        {
    
    
        var $database ='db name';
            return (@mysql_fetch_assoc($this->result));
    
        }
    
    
    
        function freeResult()
    
        {
    
            return (@mysql_free_result($this->result));
    
        }
    
    }
    
    define('_BASEURL_','http://www.mywebsite.com');	//protocol required (http://)
    
    /*
    
    define('_BASEURLCSSNEW_','http://static.css.influxive.info/greenfairnew');
    
    define('_BASEURLICONS_','http://wcons.df.influxive.info/greenfairnew');
    
    define('_BASEURLHOWITWORKS_','http://oi.how.it.influxive.info/greenfairnew');
    
    define('_BASEURLTEMPLATEIMAGE_','http://ti.ak.img.influxive.info/greenfairnew');
    
    define('_BASEURLMEDIA_','http://media.fr.influxive.info/greenfairnew');
    
    define('_BASEURLMEDIAIMAGES_','http://img.zs.ch.influxive.info/greenfairnew');
    
    */
    
    
    
    define('_BASEURLCSSNEW_','http://www.mywebsite.com/div2');
    
    define('_BASEURLICONS_','http://www.mywebsite.com/div2');
    
    define('_BASEURLHOWITWORKS_','http://www.mywebsite.com/div2');
    
    define('_BASEURLTEMPLATEIMAGE_','http://www.mywebsite.com/div2');
    
    define('_BASEURLMEDIA_','http://www.mywebsite.com/div2');
    
    define('_BASEURLMEDIAIMAGES_','http://www.mywebsite.com/div2');
    
    
    
    define('_BASEPATH_','/home/myweb/public_html');
    
    define('_IMAGESURL_',_BASEURL_.'/images');
    
    define('_IMAGESPATH_',_BASEPATH_.'/images');
    
    define('_IMAGESURLM_',_BASEURL_.'notesimages');
    
    define('_IMAGESPATHM_',_BASEPATH_.'notesimages');
    
    define('_ADMIN_MAIL_','info@mywebsite.com');
    
    define('_TITLE_','My Website | ');
    
    define('_TITLE1_','My Website ');
    
    $accepted_upload_extensions_pics = array('gif','jpg','jpeg','png');
    
    
    
    function get_uname($uid){
    
    	$sql="select * from user where id='$uid'";
    
    	$myrwd=mysql_query($sql);
    
    	$myuname=mysql_fetch_array($myrwd);
    
    	$uname=$myuname['uname'];
    
    	return $uname;
    
    }
    
    
    
    
    
    ?>

    The problem line seem to be: var $database ='db name';

    Please can someone help?
    Espresso

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    var declarations should be outside of all methods and inside the class.

    PS: This is purely a PHP error and has nothing to do with SQL
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    var declarations should be outside of all methods and inside the class.

    PS: This is purely a PHP error and has nothing to do with SQL
    How should I correct it. I am new to this. Please

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    How should I correct it.
    Check the position of other such var declarations in your code.
    I am new to this
    But you should know the purpose of having that line in your code.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Check the position of other such var declarations in your code.

    But you should know the purpose of having that line in your code.
    No I don't. It is a code I got and want to use.

  • #6
    New to the CF scene
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Espresso View Post
    No I don't. It is a code I got and want to use.
    You are the best. It worked when I placed it on the correct place. Thanks

  • #7
    New to the CF scene
    Join Date
    Apr 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Espresso View Post
    Hi, I am getting the following error:
    Parse error: syntax error, unexpected T_VARin /home/myweb/public_html/include/db.inc.php on line 216when I try to run the following script:

    Code:
    <?php
    
    
    
    class DB
    
    {
    
        // Connection parameters
    
    
    
    	var $host = 'localhost';
    
        var $user ="username";
    
        var $password ="password";
    
        var $persistent = false;
    
    	var $adminid='admin';
    
    	var $adminipwd='admin';
    
    	
    
    
    
    
    
    
    
    	// Database connection handle
    
        var $conn = NULL;
    
    
    
        // Query result
    
        var $result = false;
    
    
    
    //    function DB($host, $user, $password, $database, $persistent = false)
    
        function DB()
    
        {
    
    
    
    	}
    
    
    
        function open()
    
        {
    
            // Choose the appropriate connect function
    
            if ($this->persistent) {
    
                $func = 'mysql_pconnect';
    
            } else {
    
                $func = 'mysql_connect';
    
            }
    
    
    
            // Connect to the MySQL server
    
            $this->conn = $func($this->host, $this->user, $this->password);
    
            if (!$this->conn) {
    
                return false;
    
            }
    
    
    
            // Select the requested database
    
            if (!@mysql_select_db($this->database, $this->conn)) {
    
                return false;
    
            }
    
    
    
            return true;
    
        }
    
    
    
    
    
        function close()
    
        {
    
            return (@mysql_close($this->conn));
    
        }
    
    
    
        function error()
    
        {
    
            return (mysql_error());
    
        }
    
    
    
        function query($sql = '')
    
        {
    
            $this->result = @mysql_query($sql, $this->conn);
    
    		return ($this->result != false);
    
        }
    
    
    
        function affectedRows()
    
        {
    
            return (@mysql_affected_rows($this->conn));
    
        }
    
    
    
        function numRows()
    
        {
    
            return (@mysql_num_rows($this->result));
    
        }
    
    	function fieldName($field)
    
        {
    
           return (@mysql_field_name($this->result,$field));
    
        }
    
    	 function insertID()
    
        {
    
            return (@mysql_insert_id($this->conn));
    
        }
    
    
    
        function fetchObject()
    
        {
    
            return (@mysql_fetch_object($this->result, MYSQL_ASSOC));
    
        }
    
    
    
        function fetchArray()
    
        {
    
            return (@mysql_fetch_array($this->result, MYSQL_NUM));
    
        }
    
    
    
        function fetchAssoc()
    
        {
    
    
        var $database ='db name';
            return (@mysql_fetch_assoc($this->result));
    
        }
    
    
    
        function freeResult()
    
        {
    
            return (@mysql_free_result($this->result));
    
        }
    
    }
    
    define('_BASEURL_','http://www.mywebsite.com');	//protocol required (http://)
    
    /*
    
    define('_BASEURLCSSNEW_','http://static.css.influxive.info/greenfairnew');
    
    define('_BASEURLICONS_','http://wcons.df.influxive.info/greenfairnew');
    
    define('_BASEURLHOWITWORKS_','http://oi.how.it.influxive.info/greenfairnew');
    
    define('_BASEURLTEMPLATEIMAGE_','http://ti.ak.img.influxive.info/greenfairnew');
    
    define('_BASEURLMEDIA_','http://media.fr.influxive.info/greenfairnew');
    
    define('_BASEURLMEDIAIMAGES_','http://img.zs.ch.influxive.info/greenfairnew');
    
    */
    
    
    
    define('_BASEURLCSSNEW_','http://www.mywebsite.com/div2');
    
    define('_BASEURLICONS_','http://www.mywebsite.com/div2');
    
    define('_BASEURLHOWITWORKS_','http://www.mywebsite.com/div2');
    
    define('_BASEURLTEMPLATEIMAGE_','http://www.mywebsite.com/div2');
    
    define('_BASEURLMEDIA_','http://www.mywebsite.com/div2');
    
    define('_BASEURLMEDIAIMAGES_','http://www.mywebsite.com/div2');
    
    
    
    define('_BASEPATH_','/home/myweb/public_html');
    
    define('_IMAGESURL_',_BASEURL_.'/images');
    
    define('_IMAGESPATH_',_BASEPATH_.'/images');
    
    define('_IMAGESURLM_',_BASEURL_.'notesimages');
    
    define('_IMAGESPATHM_',_BASEPATH_.'notesimages');
    
    define('_ADMIN_MAIL_','info@mywebsite.com');
    
    define('_TITLE_','My Website | ');
    
    define('_TITLE1_','My Website ');
    
    $accepted_upload_extensions_pics = array('gif','jpg','jpeg','png');
    
    
    
    function get_uname($uid){
    
    	$sql="select * from user where id='$uid'";
    
    	$myrwd=mysql_query($sql);
    
    	$myuname=mysql_fetch_array($myrwd);
    
    	$uname=$myuname['uname'];
    
    	return $uname;
    
    }
    
    
    
    
    
    ?>

    The problem line seem to be: var $database ='db name';

    Please can someone help?
    Espresso
    Move line 216: var $database ='db name'; to the top class, before line: var $password ="password"; and test again.

    remove:
    PHP Code:
    function fetchAssoc()

        {
            return (@
    mysql_fetch_assoc($this->result));
        } 
    add to:
    PHP Code:
        var $host 'localhost';

        var 
    $user ="username";

        var 
    $password ="password";
        
        var 
    $database ='db name'


  •  

    Posting Permissions

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