'Alan listesindeki' Bilinmeyen sütun''

3 Cevap php

I) (mysql_error ile ölüyor PHP sorguda bir sql çalıştırıyorum

Unknown column '' in 'field list'

Sorgu:

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

Ben phpmyadmin sorgu çalıştırdığınızda, bu hata işaretleme olmadan bilgi dönmek

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

ve çıktısı:

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

3 Cevap

Oraya biraz daha fazla test ve hata ayıklama çıktı koyalım ...

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

Cevap basit, is not aynı sorgu yayınlanan sorgu hata getirici olduğunu olmasıdır.

Hata mesajı sorgu teşebbüs olmanın tam metnini vermiyor? Eğer hatayı bile this sorgusu oluşturuyor oluyor emin misiniz? Aynı yürütme başka biri olabilir.

Lütfen sorgu yürütüldüğünde hemen önce, aşağıdaki ifadeyi yer lütfen:


die($query);

$ Sorgu varsayarak sorgu içerir, bu yürütmek için çalışıyoruz ne exactly gösterecektir.

Her şey iyi görünüyorsa, o zaman sorgu yürütülür hemen sonra () ölürler. Eğer bir hata yoksa, o zaman daha aşağı kodda sorun için bakmak gerekir.