doubi1931 2013-09-26 19:05
浏览 30
已采纳

INSERT语句不起作用Concrete5 [关闭]

Im trying to insert some values into the DB inside a concrete5 single page and it's telling me that my syntax is wrong. I'm not sure where the syntax is wrong because i went by what was on their website. My code is Below.

<?php defined('C5_EXECUTE') or die("Access Denied.");
$db = Loader::db();
$quantity = $_POST['quantity'];
$product = $_POST['product'];
$vendor = $_POST['vendor'];
$address = $_POST['address'];
$user = $_POST['userName'];
$costcenter = $_POST['costCenter'];
$index = 0;

foreach($quantity as $info){
$num = mysql_real_escape_string($quantity[$index]);
echo "$num";
echo "</br>";
$item = mysql_real_escape_string($product[$index]);
echo "$item";
echo "</br>";
$company = mysql_real_escape_string($vendor[$index]);
echo "$company";
echo "</br>";
$shipping = mysql_real_escape_string($address[$index]);
echo "$shipping";
echo "</br>";
$person = mysql_real_escape_string($user);
echo "$person";
echo "</br>";
$center = mysql_real_escape_string($costcenter);
echo "$center";
echo "</br>";

                $sql = "INSERT INTO Orders (quantity,orderItem,vendor,shippingAddress,userName,costCenter) VALUES $num,$item,$company,$shipping,$person,$center";
                $db->Execute($sql);


$index++;

    }   

?>
  • 写回答

3条回答 默认 最新

  • doupai8095 2013-09-26 19:09
    关注

    Wrap your values in parenthesis

    $sql = "INSERT INTO Orders (quantity,orderItem,vendor,shippingAddress,userName,costCenter) VALUES ($num,$item,$company,$shipping,$person,$center)";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog