我在表单中获取数据并使用POST方法传递它并尝试在我的数据库中插入数据。我使用此代码:
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['submit'])){
$leadExecSPOC = $_POST['leadExecSPOC'];
$leadExecVertFin = $_POST['leadExecVertFin'];
$leadGenPerson = $_POST['leadGenPerson'];
$leadGenVert = $_POST['leadGenVert'];
$leadGenVertOther = $_POST['leadGenOther'];
$leadExecPerson = $_POST['leadExecPerson'];
$leadExecVert = $_POST['leadExecVert'];
$leadExecVertOther = $_POST['leadExecOther'];
$periodStart = $_POST['periodStart'];
$periodEnd = $_POST['periodEnd'];
$custName = $_POST['custName'];
$sales = $_POST['sales'];
$gp = $_POST['gp'];
$invoiceGenDate = $_POST['invoiceGenDate'];
$dateReceiptAmt = $_POST['dateReceiptAmt'];
$sql = "INSERT INTO cross(leadExecSPOC, leadExecVertFin, leadGenPerson, leadGenVert, leadGenVertOther, leadExecPerson, leadExecVert, leadExecVertOther, periodStart, periodEnd, custName, sales, gp, invoiceGenDate, dateReceiptAmt) VALUES ('$leadExecSPOC', '$leadExecVertFin', '$leadGenPerson', '$leadGenVert', '$leadGenVertOther', '$leadExecPerson', '$leadExecVert', '$leadExecVertOther', '$periodStart', '$periodEnd', '$custName', '$sales', '$gp', '$invoiceGenDate', '$dateReceiptAmt')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>
每当我运行它时,我都会收到此错误:
错误:INSERT INTO交叉(
leadExecSPOC
,leadExecVertFin
,leadGenPerson
,leadGenVert
,leadGenVertOther
,leadExecPerson
,leadExecVert
,leadExecVertOther
,periodStart
,periodEnd
,custName
,sales
,gp
,invoiceGenDate
,dateReceiptAmt
)价值观(&#39; a&#39;&#39; a&#39;&#39; a&#39;,&#39; acci-ff-cha&#39;&#39; a&#39;, &#39; a&#39;,&#39; acci-ff-cha&#39;&#39; a&#39;,&#39; 2016-05-03&#39;,&#39; 2016- 05-18&#39;,&#39; a&#39;,&#39; 1&#39;,&#39; 1&#39;,&#39; 2016-05-24&#39;,&#39 ; 2016年5月17日&#39;) 您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在“交叉(leadExecSPOC
,leadExecVertFin
,leadGenPerson
,leadGenVert
,`leadGe&#附近使用正确的语法39;第1行
MySQL版本:5.6.27-76.0
PHP版本:5.4.45
PS:已经尝试过对列名称使用反向标记。
答案 0 :(得分:2)
答案 1 :(得分:0)
更正查询语法
INSERT INTO `cross` (`leadExecSPOC`, `leadExecVertFin`, `leadGenPerson`, `leadGenVert`, `leadGenVertOther`, `leadExecPerson`, leadExecVert, leadExecVertOther, `periodStart`, periodEnd, custName, `sales`, `gp`, invoiceGenDate, dateReceiptAmt) VALUES ('$leadExecSPOC', '$leadExecVertFin', '$leadGenPerson', '$leadGenVert', '$leadGenVertOther', '$leadExecPerson', '$leadExecVert', '$leadExecVertOther', '$periodStart', '$periodEnd', '$custName', '$sales', '$gp', '$invoiceGenDate', '$dateReceiptAmt')";