我正在尝试从类到另一个文件获取一个函数但是当我运行代码时它会说“致命错误:在C:\ AppServ \ www \ store \中的非对象上调用成员函数start_order()第4行的start.php“
这是主叫代码:
<?php
@session_start();
require_once ( 'include/functions.php' );
$users->start_order();
?>
这是类和功能代码:
<meta charset='utf-8' />
<?php
require_once ( 'include/config.php' );
class users {
public function start_order () {
if($_SESSION['id']) {
$services=mysql_query("SELECT * FROM services");
print ("
<form action='<?php echo $PHP_SELF; ?>' method='post'>
<input name='orderlink' type='text'></input>
<input name='orderquantity' type='text'></input>
<input name='ordersubmit' type='text'></input>
</form>
");
$order_submit=$_POST ['ordersubmit'];
$order_link=$_POST ['orderlink'];
$order_quantity=$_POST ['orderquantity'];
if($order_submit AND !empty($order_link) AND !empty($order_quantity)){
while ($fetch_services=mysql_fetch_object($services)) {
print ("<select>");
print ("<option value='$fetch_services->id'>$fetch_services->service_name ($fetch_services->service_price)</option>");
print ("</select>"); }
} else { echo "خطاء";}
$s_id=$_POST ['service'];
$g_s_i=mysql_query("SELECT * FROM services WHERE id='$s_id'");
$fetch_service=mysql_fetch_object($g_s_i);
$s_price=$fetch_service->servic_price;
$service_n=$fetch_service->service_name;
$charge=$s_price/$order_quantity*$order_quantity;
$date=date ("Y-m-d");
$userbalance=mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]'");
$fetch_userbalance=mysql_fetch_object($userbalance);
$u_balance=$fetch_userbalance->balance;
if ($u_balance >= $charge) {
$insert_order_values=mysql_query("INSERT INTO orders(id,u_id,u_name,date,link,charge,quantity,service_name,status) VALUES ('','$_SESSION[username]','$date','$order_link','$charge','$order_quantity','$service_n','0')");
$update_balance=mysql_query("UPDATE users SET balance=$u_balance-$charge WHERE id='$_SESSION[id]'");
}
else { echo "not enough fund";}
}}}
?>
答案 0 :(得分:1)
你还没有赚到$ users。
$users = new users();
$users->start_order();
此外,最好将您的班级名称大写,因此它们看起来不像您的实例。
$users = new Users();
$users->start_order();
答案 1 :(得分:1)
您需要在使用之前创建对象的实例:
<?php
@session_start();
require_once ( 'include/functions.php' );
$users = new users();
$users->start_order();
?>