Skip navigation
Currently Being Moderated

Page won't load when I do a SQL Query

May 16, 2012 3:53 AM

I have a form where the user enters a zipcode and I'd like to do a lookup on a zipcode table so that I can store the City/ State in a hidden field that will be stored in a MySQL table when the user clicks "Submit".  When the "Submit" button is clicked it launches a javascript script shown below, I had to comment out several of the lines just to get the page to load, this ought to be easy but I can't even get the page to load without all the commented out lines below, The page that loads is here , I added a line "echo 'testecho'" and that value appears in the MySQL table so I know the script is being triggered and I'm populating the hidden field with a test value. First I need to get the page to load. Can anyone suggest what am I doing wrong? Thanks for any suggestions, it must be blindingly obvious but I just can't see the problem after staring at it for hours.


<script type="text/javascript">
function getCitySt(){

// Store the zip code in the location field incase it's invalid
document.form1.location.value =;


document.form1.location.value = "<?php

// Make a MySQL Connection

$query = "SELECT zipcodes.citystate FROM zipcodes WHERE zipcodes.zipcode =";
// $result = mysql_query($query) or die(mysql_error());

// Print out result
// while($row = mysql_fetch_array($result)){
//  echo $row['citystate'];
echo 'testecho';
// }


More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points