'字段列表'中的未知列''

时间:2010-03-31 18:05:49

标签: php mysql

我正在使用mysql_error()

运行PHP查询中的sql
Unknown column '' in 'field list'

查询:

SELECT `standard` AS fee FROM `corporation_state_fee`  WHERE `stateid` = '8' LIMIT 1

当我在PHPmyadmin中运行查询时,它返回信息而不标记错误

编辑: 我为没有发布足够的信息而道歉;以下是问题所在的整个代码块

    switch($lid){
        case '460':
            $tbl = $corporation_state_fee_tbl;
            break;
        case '535':
            $tbl = $llc_state_fee_tbl;
            break;
        default:
            return 0;
            break;
    }
    var_dump("SELECT `".$processing."` AS fee FROM `".$tbl."` WHERE `stateid` = '".$state."' LIMIT 1");
    $sql = mysql_query("SELECT `".$processing."` AS fee FROM `".$tbl."` WHERE `stateid` = '".$state."' LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_array($sql);
    $fee = $row['fee'];
    include(CONN_DIR."disconnect.php"); 

,输出为:

  

string(83)“SELECT standard AS费用来自corporation_state_fee WHERE stateid ='8'限制1”   “字段列表”中的未知列“”

3 个答案:

答案 0 :(得分:0)

简单的答案是您发布的查询不是生成错误的查询。

错误消息是否未提供正在尝试的查询的完整文本?你确定它甚至这个查询产生了错误吗?可能是同一执行中的另一个。

答案 1 :(得分:0)

在您的查询执行之前,请放置以下声明:


die($query);

假设$ query包含您的查询,这将显示完全您要执行的内容。

如果一切顺利,那么在执行查询后立即执行die()。如果您没有收到错误,那么您需要在代码中进一步查找问题。

答案 2 :(得分:0)

让我们再添加一些测试和调试输出......

switch($lid){
  case '460':
    $tbl = $corporation_state_fee_tbl;
    break;
  case '535':
    $tbl = $llc_state_fee_tbl;
    break;
  default:
    return 0;
    break;
}

if ( !isset($processing, $tbl, $state) ) {
  die("something's missing");
}
// hopefully _all_ those variable parts are "safe"?

// use multiple lines so the error location is a bit more expressive
// ... and I find it easier to read this way
$query = "
  SELECT
    `".$processing."` AS fee
  FROM
    `".$tbl."`
  WHERE
    `stateid` = '".$state."'
  LIMIT
    1
";

// please copy&paste the output of the next line
echo '<pre>Debug: query=', htmlspecialchars($query), '</pre>';
$sql = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($sql);
if ( false===$row ) {
  // no such record
  return 0;
}
$fee = $row['fee'];
include(CONN_DIR."disconnect.php");
相关问题