Hi,
I am having problem with my code can anybody help it is giving me this error
Parse error: parse error, expecting `T_FUNCTION'on line 4.
Here is my code

<?php class database
{
$dbconnect=NULL;
$dbhost="localhost";
$dbuser="root";
$dbpass="";
$dbname="db_student_info";
function db_connect()
{

global $dbhost,$dbuser,$dbpass,$dbname;
if(!$dbconnect)
$dbconnect=mysql_connect($dbhost,$dbname,$dbpass);
if(!$dbconnect)
{return 0;}
else if(!mysql_select_db($dbname))
{
return 0;
}
else{
return $dbconnect;
}
}
}?>
thanx in advance

Here's the correct code:

<?php class database
{
var $dbconnect=NULL;
var $dbhost="localhost";
var $dbuser="root";
var $dbpass="";
var $dbname="db_student_info";
function db_connect()
{

global $dbhost,$dbuser,$dbpass,$dbname;
if(!$dbconnect)
$dbconnect=mysql_connect($dbhost,$dbname,$dbpass);
if(!$dbconnect)
{return 0;}
else if(!mysql_select_db($dbname))
{
return 0;
}
else{
return $dbconnect;
}
}
}?>

Variables are defined by var and functions by function.

More specifically: Class variables (properties) need to be declared with public, private or protected. Declaration with var (public) is supported for compatibility reasons. You can read more here.

thanx i have solved the problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.