Php 将变量保存到数据库时出错
我正在尝试将文章和标题保存到我的数据库中。我在mysqli中使用OOP编程语言(getter、setter)。在这里,您可以看到我在类中的代码Php 将变量保存到数据库时出错,php,database,mysqli,Php,Database,Mysqli,我正在尝试将文章和标题保存到我的数据库中。我在mysqli中使用OOP编程语言(getter、setter)。在这里,您可以看到我在类中的代码 <?php class Article { private $m_sTitle; private $m_sArticle; public function __set($p_sProperty, $p_vValue) { switch($p_sProperty) { ca
<?php
class Article {
private $m_sTitle;
private $m_sArticle;
public function __set($p_sProperty, $p_vValue)
{
switch($p_sProperty)
{
case "Title" :
$this -> m_sTitle = $p_vValue;
break;
case "Article" :
$this -> m_sArticle = $p_vValue;
break;
}
}
public function __get($p_sProperty)
{
$vResult = null;
switch($p_sProperty)
{
case "Title" :
$vResult = $this -> m_sTitle;
break;
case "Article" :
$vResult = $this -> m_sArticle;
break;
}
}
public function saveArticle()
{
include("connection.php");
$sSql = "INSERT INTO tblArticles
(titel,
article,
)
VALUES
('".mysqli_real_escape_string($mysqli, $this -> m_sTitle) . "',
'" .mysqli_real_escape_string($mysqli, $this -> m_sArticle) . "',
);";
if (!$mysqli -> query($sSql))
{
throw new Exception("Something went wrong");
}
}
}
?>
我收到此错误:致命错误:未捕获异常“exception”,在../assets/article.class.php:48堆栈跟踪:#0../index.php(52):article->saveArticle()#1{main}抛出..assets/article.class.php,在第48行(这一行$article1=new article;)
谢谢你的回复
通过替换查询(类型错误)解决问题,您可以在这句话下面看到工作部分(查询)。
$sSql = "INSERT INTO tblArticles
(titel,
article
)
VALUES
('".mysqli_real_escape_string($mysqli, $this -> m_sTitle) . "',
'" .mysqli_real_escape_string($mysqli, $this -> m_sArticle) . "');";
在您的查询中,
文章
后面有一个不需要的逗号:
INSERT INTO tblArticles
(titel,
article,) VALUES ...
你能把桌子的结构贴出来吗?你是我的人!你说的地方有很多,我的问题也有很多!现在一切正常。非常感谢你的回答!
INSERT INTO tblArticles
(titel,
article,) VALUES ...