1
votes

I am running a sql in PHP query that is dieing with the mysql_error() of

Unknown column '' in 'field list'

The query:

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

when I run the query in PHPmyadmin, it return the information without flagging the error

EDIT: I apologize for not posting enough information; the following is the entire code block where the problem is

    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"); 

and the output is :

string(83) "SELECT standard AS fee FROM corporation_state_fee WHERE stateid = '8' LIMIT 1" Unknown column '' in 'field list'

3
Are you really sure this is really, exactly, the query that is sent to the database from your PHP code ? (asking this as a comment, this time ^^ ) - Pascal MARTIN
I just edited the question to fix the formatting error to exactly what the query listed it - Rixius
Time to stop nickel and diming us with tiny bits of info - post more of the script with the context around the query so we can see what's going on. - Peter Bailey
Try running another simple query instead and see what happens. Try SELECT * FROM corporation_state_fee WHERE stateid = 8 - thetaiko

3 Answers

0
votes

The simple answer is that the query you posted is not the same query that is generating the error.

Does the error message not give the full text of the query being attempted? Are you sure it's even this query that is generating the error? Could be another one in the same execution.

0
votes

Just before your query is executed, please place the following statement:


die($query);

Assuming $query contains your query, this will display exactly what you are trying to execute.

If all looks well, then die() right after the query is executed. If you don't get an error then you need to look for your problem further down in your code.

0
votes

Let's put some more tests and debug output in there...

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");