我正在构建动态查询,而且我很难搞清楚这个错误代码:
错误:您的SQL语法出错;查看与您的MariaDB服务器版本对应的手册,以获得正确的语法,以便在''''品牌'''''''' 39;类型',' c型'' POE''功能''透镜''价格& #39;)价值观(' un'第1行
这是我的PHP:
<?php
include("config.php");
$cameraCol = array("'image'", "'brand'", "'model'", "'type'", "'c-type'", "'poe'", "'specs'", "'lens'", "'price'");
$accessoriesCol = array("image", "brand", "model", "price");
$cableCol = array("image", "brand", "model", "type", "price");
$powerCol = array("image", "brand", "model", "channels", "price");
$recorderCol = array("image", "brand", "model", "type", "poe", "specs", "ports", "price");
$routerCol = array("image", "brand", "model", "wireless-capability", "price");
$switchCol = array("image", "brand", "model", "ports", "price");
$wirelessCol = array("image", "brand", "model", "frequency", "speed", "price");
$category = $_POST['category'];
if($category == "camera"){
$cameraImp = implode(",", $cameraCol);
$cameraVal = array("'".$_POST['image']."'", "'".$_POST['brand']."'", "'".$_POST['model']."'", "'".$_POST['type']."'", "'".$_POST['c-type']."'", 1, "'".$_POST['specs']."'", "'".$_POST['lens']."'", $_POST['price']);
$cameraVal = implode(",", $cameraVal);
insertItem($cameraImp, $category, $cameraVal);
}
function insertItem($columns, $category, $cameraValArr){
include("config.php");
$sql2 = "INSERT INTO ". $category ."(". $columns .") VALUES(". $cameraValArr .")";
$result2 = mysqli_query($conn, $sql2);
if(!$result2){
die("Error: " . mysqli_error($conn));
}
}
?>
这显然是我的查询中的一个错误,我很确定我错过了一些东西。任何帮助将不胜感激!
答案 0 :(得分:0)
解决方案:从我的数据库中的列名中删除连字符,特别是&#34; c-type&#34;列。