【问题标题】:codeigniter form sql errorcodeigniter表单sql错误
【发布时间】:2015-06-25 19:26:34
【问题描述】:

这里出了点问题。我在提交时收到错误:这需要是一个简单的下拉选项,您可以在其中选择 2 个提示...

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 ORDER BY int_displayorder ASC 附近使用正确的语法 SELECT var_price_label1,var_price_label2,var_price1,var_price2 FROM dis_activity where int_glcode= ORDER BY int_displayorder ASC

文件名:/home/discou60/public_html/beta/modules/reservationleads/models/reservationleads_model.php 行号:1337

$SQL = $this->db->query("SELECT var_price_label1,var_price_label2,var_price1,var_price2 FROM " . DB_PREFIX . "activity where int_glcode=$tagid ORDER BY int_displayorder ASC");
    $RS = $SQL->Result();
    $Html = "";
    $Html .= "<select name='int_no_of_people' id='int_no_of_people' ><option value=''> Choose Your charter</option>";
    foreach ($RS as $Row) {
        $selected = "";
        if (!empty($tagid) && $tagid == $Row->int_glcode) {
            $selected = "selected='selected'";
        }
         $Html .= "<option $selected value='" . $Row->var_price1 . "'>" . $Row->var_price_label1 . "</option>";
         $Html .= "<option  value='" . $Row->var_price2 . "'>" . $Row->var_price_label2 . "</option>";
    }


    $Html .= "</select>";

    return $Html;

【问题讨论】:

  • 除了你显示的代码中没有ORDER BY...
  • where int_glcode= ORDER BY 肯定有错误。它是在哪里/如何生成的,我不知道。所以这部分where int_glcode= 缺少一些没有被填充的东西。
  • 所以你的 $tagid 变量是空的。在将其添加到查询之前,您应该检查它的值。
  • where int_glcode=$tagid 是它失败的地方。 $tagid 没有被填充。可能需要引用;很难说。
  • @jeroen 应该将您的评论作为答案;-)

标签: php mysql codeigniter


【解决方案1】:

检查$tagid是否不为空,替换sql字符串如下

...where int_glcode = '".$tagid."' ORDER BY int_displayorder ASC...

【讨论】:

  • 这里同样适用于我在另一个答案中留下的内容。
  • ELECT var_price_label1,var_price_label2,var_price1,var_price2 FROM dis_activity where int_glcode=\''.73.'\' ORDER BY int_displayorder ASC
【解决方案2】:

错误是明确地并且准确地告诉你问题...

... int_glcode= ORDER BY int_displayorder ASC ...

您忘记在WHERE 子句比较中放置一个。显然,$tagid 在您构建该字符串时为空(或至少没有有意义的字符串表示形式)。 (这是因祸得福,因为$tagid 可能包含任何东西,并且有可能被 SQL 注入。)

【讨论】:

  • 这已经在 cmets 中建立了,我可能会添加相当多的内容。
  • @Fred-ii-:也许我没有理解你的意思,但是……所以呢?这是错误的确切原因。也许如果 OP 提供更多上下文,我们可以到达 why $tagid 没有被填充,但要问的问题是简单地解释错误消息。这正是对此的解释。
  • 如果到目前为止给出的任何答案都被否决了,我希望你们都事先知道它不会来自我; 只是说
  • { $tagid = $this->input->get_post('fk_location');} 和 int_glcode 一样
  • @AleksandarMilisavljevic:那段代码发生在哪里?您如何确认找到了有效值?当你调试这个时,当你声明那个 SQL 字符串时,$tagid 的实际值是多少?
猜你喜欢
  • 2012-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
  • 1970-01-01
  • 2010-12-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多