MYSQL PHP Trying to display a result
Posted: Fri Mar 04, 2011 3:58 am
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
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