Php Mysql数据库查询错误

时间:2013-01-11 22:33:33

标签: php

基本上,从我发的表格发送customer_name并使用此代码,我将其拉出并将其与时间一起保存到数据库中。这段代码一直给我这个错误:

  

致命错误:在第19行的/home/projectu/public_html/sub/save.php中不在对象上下文中时使用$ this

注意:第19行是这一行:

$db->query($queryone);

这是我的代码:

整个Save.php

include('db-config.php');

$customer_name = $_POST['customername'];

/* Kaspersky */
$kaspersky_date = strtotime("+11 months").'|'.strtotime("+12 months");
$kaspersky = explode("|", $kaspersky_date);
$kaspersky_temp = "$customer_name got new kaspersky.";

/* PC Picked-UP */
$pickedups_date = strtotime("+1 months");
$pickedups_temp = "$customer_name picked up his computer.";


if(isset($_POST['kaspersky'])) {
$queryone = "INSERT INTO sublist (scheduled_date, customer_name, kaspersky_status, kaspersky_template)
                       VALUES ($kaspersky[0], $customer_name, YES, $kaspersky_temp)";

$this->query($queryone);

$querytwo = "INSERT INTO sublist (scheduled_date, customer_name, kaspersky_status, kaspersky_template)
                       VALUES ($kaspersky[1], $customer_name, YES, $kaspersky_temp)";

$this->query($querytwo);

}
if(isset($_POST['pickeduppc'])) {
$query = "INSERT INTO sublist (scheduled_date, customer_name, pcpickup_status, pcpickup_template)
                       VALUES ($pickedups_date, $customer_name, YES, $pickedups_temp)";
}

1 个答案:

答案 0 :(得分:1)

您不能在非对象或静态方法中使用$this。你应该创建一个新对象。

$db = new mysqli(......);
$db->query("SELECT ... FROM...");