-1

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

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

注意:第 19 行是这一行:

$db->query($queryone);

这是我的代码:

整个保存.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)";
}
4

1 回答 1

1

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

$db = new mysqli(......);
$db->query("SELECT ... FROM...");
于 2013-01-11T22:52:38.813 回答