0

I am trying to call specific rows from one table with links such as:

<a href="http://www.southfloridacoastalproperty.com/fusioncharts/sqftchart-db-2col-test-link.php?zip_ref=c33004">
    33004
</a>
<br>
<a href="http://www.southfloridacoastalproperty.com/fusioncharts/sqftchart-db-2col-test-link.php?zip_ref=c33009">
    33009
</a>
<br>

The column name is zip_ref and I'm trying to just display rows of a certain zip code, for instance 33004.

But when I try any of my links I get the following error:

Error code (1054): Unknown column 'c33004' in 'where clause'

But my where clause is defining the column zip_ref isn't it and isn't = c33004 searching for any values under that column??

$zip_ref = mysqli_real_escape_string($dbhandle, $_GET["zip_ref"]);
$strQuery = "SELECT id, zip_code, zip_ref, year, price_avg_sold, price_sqft, pct_list_sold, adom, sold_nu, sold_chg, year_1, year_2, year_3, year_4, year_5, year_6, year_7, year_8, year_9, year_10
             FROM zip_code_data
             WHERE zip_ref = ". $zip_ref ."
             ORDER BY year ASC";
TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94

1 Answers1

0

If you want to use string literals in your query, you will have to wrap them in apostrophes:

$strQuery = "SELECT id, zip_code, zip_ref, year, price_avg_sold, price_sqft, pct_list_sold, adom, sold_nu, sold_chg, year_1, year_2, year_3, year_4, year_5, year_6, year_7, year_8, year_9, year_10
             FROM zip_code_data
             WHERE zip_ref = '". $zip_ref ."'
             ORDER BY year ASC";

If you don't do that, the literal (e.g. c33004) will be treated as a column name.


An even better and saver solution would be to use prepared statements. You should definitely look into this topic.

TimoStaudinger
  • 41,396
  • 16
  • 88
  • 94