Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql数据库查询错误_Php - Fatal编程技术网

Php Mysql数据库查询错误

Php Mysql数据库查询错误,php,Php,基本上,从我制作的表单中,我发送customer\u name,并使用此代码将其拉入数据库并随时间一起保存。此代码一直给我以下错误: 致命错误:在第19行的/home/projectu/public_html/sub/save.php中不在对象上下文中时使用$this 注:第19行是这一行: $db->query($queryone); 这是我的密码: 整个Save.php include('db-config.php'); $customer_name = $_POST['custo

基本上,从我制作的表单中,我发送
customer\u 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)";
}

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

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

您确定正在查看正确的文件吗?在save中向我们显示代码看起来不对。php@Extelliqent
db config.php
中的代码是什么?无论如何,
$this
是一个神奇的变量名,仅保留在对象实例上下文中使用。不能在上述过程脚本中使用它。您需要查看如何创建MySQLi对象以及如何将其传递到上述脚本中。@Extelliqent好的,只需将两个文件中的
$this
重命名为
$db
,它就可以工作了。@Extelliqent您现在将收到MySQL语法错误,因为您在查询中没有引用任何字符串。输出查询字符串,您将了解我的意思。谢谢。我想我的问题也错了。。