tags:

views:

111

answers:

3

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'

A: 

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.

Peter Bailey
That is the entire string that mysql_error() is returning. And it is the only sql query in the script.
Rixius
A: 

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.

Syntax Error
the PHP i'm using (exactly copy and pasted) is: $sql = mysql_query("SELECT `".$processing."` AS fee FROM `".$tbl."` WHERE `stateid` = '".$state."' LIMIT 1") or die(mysql_error());
Rixius
and the query I listed at the top is the var_dumped string of "SELECT ".$processing." AS fee FROM ".$tbl." WHERE stateid = '".$state."' LIMIT 1" the line before running the query
Rixius
A: 

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");
VolkerK
problem was $processing was not being set properly.Sorry for all the trouble guys.
Rixius
the ```'s were passing an empty parameter since $processing was empty. adn so mysql was trying to find a column of ''
Rixius