I'm fairly new at PHP and so maybe this is a simple question. This is a class I use to update a database. The problem is that it keeps giving me an error at the line marked * because it can't find $con, which is clearly in the function openconn(). It seems I can't pass the connection to another function. Am I doing something wrong?Thanks
class retreats {
public $retreat_name = '';
function openconn() {
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("PHPTest", $con);
}
function closeconn(){
mysql_close($con);
}
function add_retreat(){
openconn();
$sql="INSERT INTO tbl_retreats (retreat_name) VALUES ('".$this->retreat_name."')";
if (!mysql_query($sql,$con)) *******
{
die('Error: ' . mysql_error());
}
echo "Record Successfully Added";
closeconn();
}
}
$confromopenconn()