0
我想從一個函數從類到另一個文件,但是當我運行代碼它說:「致命錯誤:調用成員函數start_order()在非對象在C:\第4" 行的appserv \ WWW \店\ 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";}
}}}
?>
僅供參考到OP,在'創建實例時,除非在構造函數需要參數()'是可選的。您可以輕鬆執行'$ users = new users;' – 2014-11-05 19:11:26