Php Mysql数据库查询错误

问题描述:

基本上,从我制作的表单我发送customer_name,并将此代码与此代码一起拖出并与时间一起保存到数据库中。此代码一直给我这个错误:Php Mysql数据库查询错误

Fatal error: Using $this when not in object context in /home/projectu/public_html/sub/save.php on line 19

注: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)"; 
} 
+0

'$ this'只能在对象方法中使用。如果在对象之外使用它将会失败。 – datasage

+0

那么$ db的值是多少?以及该对象的查询方法是什么? –

+0

我想要做的就是运行插入查询。我怎么做?连接数据库我使用mysqli – Extelliqent

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

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

感谢您。我想我的查询也是错误的.. – Extelliqent