473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

newbie sql error - wrong syntax in select query

cassbiz
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.
[php]
<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" />
</form>

<?

$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>';
}

?>
[/php]

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


Thanks in advance
Frank Casser
Oct 25 '06 #1
5 2161
cassbiz
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>';
  2.  
is there a way to write the output into straight HTML ?
Oct 25 '06 #2
ronverdonk
4,258 Expert 4TB
But your output line generates straight HTML or do you mean something else?

Ronald :cool:
Oct 25 '06 #3
cassbiz
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
ronverdonk
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
cassbiz
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

14
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
0
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...
2
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)...
7
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...
4
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?...
7
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...
16
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...
2
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 ,...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.