基本的mysqli插入查询不起作用

时间:2015-12-14 02:04:15

标签: mysqli

任何人都可以发现此查询的问题? 我被困在项目的这个小部分但是看不到错误。

$mysqli->query("INSERT INTO item (name, description, buyPrice, price, qty, brandID, primaryCategoryID, secondaryCategoryID, thirdCategoryID, supplierID) VALUES ('{$_POST['name']}', '{$_POST['description']}', '$buyPrice', '$price', '{$_POST['Qty']}', '{$_POST['brandID']}', '{$_POST['primaryCategoryID']}', '{$_POST['secondaryCategoryID']}', '{$_POST['thirdCategoryID']}', '{$_POST['supplierID']}')");

查询无效。

以下UPDATE查询完美地运行,并确保在这两种情况下都正确传递$ _POST变量:

$mysqli->query("UPDATE item SET name = '{$_POST['editInventoryName']}', description = '{$_POST['editInventoryDescription']}', buyPrice = '$buyPrice', price = '$price', brandID = '{$_POST['editInventoryBrand']}', supplierID = '{$_POST['editInventorySupplier']}', primaryCategoryID = '{$_POST['editInventoryPrimaryCat']}', thirdCategoryID = '{$_POST['editInventoryThirdCat']}', secondaryCategoryID = '{$_POST['editInventorySecondaryCat']}' WHERE id = '{$_POST['editInventoryID']}'");

2 个答案:

答案 0 :(得分:0)

删除$_POST varibles周围的括号:

$mysqli->query("INSERT INTO item (name, description, buyPrice, price, brandID, primaryCategoryID, secondaryCategoryID, thirdCategoryID, supplierID) VALUES ('".$_POST['name']."', '".$_POST['description']."', '".$buyPrice."', '".$price."', '".$_POST['brandID']."', '".$_POST['primaryCatergoryID']."', '".$_POST['secondaryCategoryID']."', '".$_POST['thirdCatgoryID']."', '".$_POST['supplierID']."')");

答案 1 :(得分:0)

问题是$ _POST变量被传递为空,因此查询没有执行。

对不起编码太多小时的愚蠢问题了! :)

相关问题