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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化