PHP Class extension does not seem to work
And so, I had a class defined on config.php. BUt , I cannot get the class extend done in another file (calc.php).
So, this is the calc.php:
error_reporting(0);
define('BASE_PATH','some_path');
include_once(BASE_PATH.'\config\config.php');
class Calc extends Main
{
var $conn;
var $table;
var $query;
var $where;
function connect_db($connect)
{
$connect = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
or die ("Got problem");
mysql_select_db(DB_DATABASE)
or die ("Error: Can't access database");
$this->connect = $conn;
}
function calc()
{
if(isset($_POST['num_a']))
$num_a = $_POST['num_a'];
if(isset($_POST['num_b']))
$num_b = $_POST['num_b'];
if(isset($_POST['num_c']))
$num_c = $_POST['num_c'];
if(isset($_POST['num_d']))
$num_d = $_POST['num_d'];
if(isset($_POST['num_e']))
$num_e = $_POST['num_e'];
if(isset($_POST['num_f']))
$num_f = $_POST['num_f'];
if(isset($_POST['num_g']))
$num_g = $_POST['num_g'];
if(isset($_POST['num_h']))
$num_h = $_POST['num_h'];
if(isset($_POST['num_i']))
$num_i = $_POST['num_i'];
if(isset($_POST['num_j']))
$num_j = $_POST['num_j'];
$total_deduct = $num_b + $num_c + $num_d + $num_e + $num_f + $num_g + $num_h + $num_i + $num_j;
$total_nett = $num_a - $total_deduct;
if($num_a < $total_deduct)
$num_a * -1;
if($this->connect == 1)
{
$query = "INSERT INTO tbl_current_deductions
(num_a,num_b,num_c,num_d,num_e,num_f,num_g,num_h,num_i,num_j)
VALUES";
if($query)
{
if(mysql_num_rows($query) == 1 )
{
return true;
开发者_如何学编程 }
else
{
trigger_error("SQL", E_USER_ERROR);
return false;
}
}
echo "<meta http-equiv='refresh' content='3;url=http://localhost/some_path'>
<table width='100%' border='0' cellspacing='0' cellpadding='1'>
<tr>
<td align ='center'>
<p style='font: 11pt Arial Rounded MT Bold; color:#999999;'>
Nett balance is ". $total_nett." <br/>
Total deduction is ". $total_deduct."
</p>
</td>
</tr>
</table>";
}else{
exit;
}
}
}
It seems you did not instanciate any Calc object, nor that you called the calc()
method on it.
精彩评论