Hello. I am new to PHP and mySQL. I am trying to enter a zipcode into a form and return the price associated with the zip code.
Here is my code.
MY Form
<form action="pricezip.php" method="post">
ZIP CODE:<br/>
<input type="text" value="<?php echo $zip;?>" name="zip"/>
<br/>
<input type="submit" value="submit changes"/>
</form>
----------------------------------
MySQL query
<?php
mysql_connect("blah","blah","blah") or die("Error: ".mysql_error());
mysql_select_db("blah");
$zip = $_POST['zip'];
$sql = mysql_query("select price from ID where zip =" ' %$zip%'');
while ($results = mysql_fetch_array($sql)){
echo 'ID: '.$results['ID'];
echo '<br/>ZIP: '.$results['zip'];
echo '<br/> Price: '.$results['price'];
echo '<br/> Round Trip Price: '.$results['rt'];
echo '<br/><br/>';
}
?>
Can someone maybe help me out.
My table in SQL looks like this and my table name is ID.
zip price rt
97006 45 85
97232 40 75
MYSQL PHP Trying to display a result
Moderator: General Moderators
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Re: MYSQL PHP Trying to display a result
1. where do you set the value for $zip in the form?
2. In
Do you want the $zip variable to be an EXACT match with the table value
OR do you want to see if it is part of the value
NOTE: your use of single an double quotes need to open and close properly
2. In
Code: Select all
$sql = mysql_query("select price from ID where zip =" ' %$zip%'');Code: Select all
$sql = mysql_query("select price from ID where zip = '$zip'");Code: Select all
$sql = mysql_query("select price from ID where zip LIKE '%$zip%''');Re: MYSQL PHP Trying to display a result
I finally figured it out.. but still working on the overall form..
I have figured out how to post the data and search the database..
But I am thinking I want to implement AJAX or Jquery to make the
UI of the form a little more attractive.. So, now I am learning about that.
Anyone who has a good link for mysql php and ajax, I would appreciate it.
I have figured out how to post the data and search the database..
But I am thinking I want to implement AJAX or Jquery to make the
UI of the form a little more attractive.. So, now I am learning about that.
Anyone who has a good link for mysql php and ajax, I would appreciate it.