MySQL Query SELECT parameters? Re: Where
Posted: Wed Jan 25, 2006 1:13 pm
Having to use PHP v4, I have a MySQL Database: b16124 with TABLE: wd_user,
and I want to Pull Fields userid, company_name, city, state. But only where state is equal to a specific state passed/posted from previous page as $searchstate.
I receive the following ERROR;
Invalid query: Unknown column 'FL' in 'where clause
From the following PHP code;
Any suggestions as to what to put for WHERE ?
Thanks!
SRR/arr
and I want to Pull Fields userid, company_name, city, state. But only where state is equal to a specific state passed/posted from previous page as $searchstate.
I receive the following ERROR;
Invalid query: Unknown column 'FL' in 'where clause
From the following PHP code;
Code: Select all
$query = sprintf("SELECT userid, company_name, city, state, phone FROM wd_users WHERE state=$searchstate",
mysql_real_escape_string($company_name));
mysql_select_db('b16124', $db)
or die("Could Not Open Database: ".mysql_error());
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
die($message);
}
$num_rows = mysql_num_rows( $result );
print "<H3>Number of listings found: $num_rows</h3>";
while ( $row = mysql_fetch_array( $result ) )
{
for ($i=0; $i < $mysql_num_rows; $i++)
print "<p><strong>Business Name: <a href=members/index.php?id=";
print $row['userid'].">";
print $row['company_name'];
print "</a></strong><br />City: ";
print $row['city'];
print "<br />Phone: ";
print $row['phone'];
print "</p>";
}
mysql_free_result($result);
mysql_close( $db );Thanks!
SRR/arr