我正在使用管理面板表单,我在连接表单页面到mysql时遇到问题..我创建了表名:main_settigns
并且我正在使用MVC ..这是表格控制器: -
enter code here
<?php
if(isset($_POST['submit']) && $_POST['submit'] == "Update")
{
$mainsettings['site_name'] = $_POST['site_name'];
$mainsettings['site_url'] = $_POST['site_url'];
$mainsettings['site_desc'] = $_POST['site_desc'];
$mainsettings['site_email'] = $_POST['site_email'];
$mainsettings['site_tags'] = $_POST['site_tags'];
$mainsettings['site_homapanel'] = $_POST['site_homapanel'];
$mainsettings['fb'] = $_POST['fb'];
$mainsettings['tw'] = $_POST['tw'];
$mainsettings['yt'] = $_POST['yt'];
$mainsettings['username'] = $_POST['username'];
try {
include 'models/Arageek.php';
include 'models/Add.php';
$addmMainSettings = new Add($mainsettings, "main_settigns");
if($addmMainSettings == TRUE)
{
echo 'successfully Added';
}
}
catch (Exception $exc)
{
echo $exc->getMessage();
}
}
else
{
try {
include 'models/Arageek.php';
include 'models/Display.php';
$data = new Display("main_settigns");
$displayData = $data->getData();
} catch (Exception $exc)
{
echo $exc->getMessage();
}
include 'views/v_mainSettings.php';
}
?>
这是模型页面: -
enter code here
<?php
/* add class
* insert the data into mysql database
* @author Dev.Yasser
*/
class Add extends Arageek
{
private $data;
private $tablename;
private $cxn;
public function __construct($data, $tablename)
{
if(is_array($data))
{
$this->data = $data;
$this->tablename = $tablename;
}
else
{
throw new Exception("Error: the data must be in an array .");
}
$this->connectToDB();
$this->AddData($this->data);
$this->close();
}
// insert the data into the table
function AddData($data)
{
foreach ($data as $key=> $value)
{
$keys[] = $key;
$values[] = $value;
}
$tblKeys = implode($keys, ",");
$dataValues = '"'. implode($values, '","') .'"';
$query = "INSERT INTO $this->tablename ($tblKeys) VALUES ($dataValues)";
if($sql = mysql_query($query))
{
return TRUE;
}
else {
throw new Exception("Error: Can not excute the query");
return FALSE;
}
}
}
?>
和父类: -
enter code here
<?php
class Arageek {
private $cxn;
function connectToDB()
{
include 'models/Database.php';
$vars = "include/vars.php";
$this->cxn=new Database($vars);
}
function close()
{
$this->cxn->close();
}
}
?>
提交表单后的结果是:&#34;错误:无法执行查询&#34;