472,983 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 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 2148
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

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

Similar topics

by: sam | last post by:
When I run this SQL query: SELECT u.*, o.* FROM users u, orders o WHERE TO_DAYS(o.order_date) BETWEEN TO_DAYS('2003-09-20')-10 AND TO_DAYS('2003-09-20')+10
by: Morten Gulbrandsen | last post by:
C:\mysql\bin>mysql -u elmasri -pnavathe company Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 29 to server version: 4.1.0-alpha-max-debug Type...
by: Jammy G | last post by:
Hello, In the below SQL I am getting Error at COUNT. Can anyone tell me what is wrong with this query: SELECT DISTINCT A.EMP_NO, A.ENT_DT, CASE A.SHIP_NO WHEN (SELECT COUNT(DISTINCT SHIP_NO)...
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password...
by: Johnny Ruin | last post by:
What do you think of a query that generates a System.Data.SqlClient.SqlException when submitted via a application, but when run through QueryAnalyzer or EnterpriseManager doesn't generate a error?...
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
by: lawrence k | last post by:
I've made it habit to check all returns in my code, and usually, on most projects, I'll have an error function that reports error messages to some central location. I recently worked on a project...
by: Baldaris | last post by:
Hi I am using Xampp , Php 5.2.6 and phpedit for wiriting code. i am trying to add the content's from user form and then add then into the data base. It check's if submit is clicked or not ,...
by: benicio | last post by:
The subject update failed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = 6' at line 5. This is...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.