471,093 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,093 software developers and data experts.

newbie sql error - wrong syntax in select query

202 100+
I am having a problem getting a simple form to work. I keep getting an error in the select statement.

Error performing query: Unknown column '$zip' in 'where clause'

below is my code and it is driving me nuts. What am I doing wrong?

Read the Posting Guidelines before you post anything!!
Edited for eadability reasons.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Please type in your billing Zip Code:<br />
<input type="text" name="zip" />
</label><br />
<input type="submit" value="Submit" />


$zip = $_POST['zip'];

echo '<p>Zip Code:</p>';

// Request Zip Code Information
$result = @mysql_query('SELECT zip, city, state FROM zip WHERE zip=$zip');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');

// Display the text of zip in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['zip'], $row['city'], $row['state']. '</p>';


In the select statement, if I type in the value directly it works fine.

Thanks in advance
Frank Casser
Oct 25 '06 #1
5 2000
202 100+
The 'zip' field is an INT field and is also the primary key.

I see what I did wrong and now the script is working. I used a ' instead of a " and that threw everything off.

One more question if I may.

Expand|Select|Wrap|Line Numbers
  1. echo '<p>' . $row['zip'], $row['city'], $row['state']. '</p>';
is there a way to write the output into straight HTML ?
Oct 25 '06 #2
4,258 Expert 4TB
But your output line generates straight HTML or do you mean something else?

Ronald :cool:
Oct 25 '06 #3
202 100+
But your output line generates straight HTML or do you mean something else?

Ronald :cool:

In regards to formatting the string, I would like to add spacing and change the font.
Oct 25 '06 #4
4,258 Expert 4TB
You can do that either by
1. having a CSS class defined before and using that class in your echo:
[php]echo "<p class='xyz'>{$row['zip']}, {$row['city']}, {$row['state']}'</p>";[/php]
2. Defining the CSS characteristics directly in a style attribute of the <p> tag:
[php]echo "<p style='font-family:verdana,arial,sans serif; font-size:12px;font-weight:bold;'>{$row['zip']}, {$row['city']}, {$row['state']}'</p>";[/php]
Ronald :cool:
Oct 25 '06 #5
202 100+
Thanks Ron,

It just appeared that I was using too many single quotes. I appreciate the help.
Oct 25 '06 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

14 posts views Thread by sam | last post: by
reply views Thread by Morten Gulbrandsen | last post: by
2 posts views Thread by Jammy G | last post: by
4 posts views Thread by Johnny Ruin | last post: by
7 posts views Thread by John Øllgård Jensen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.