MYSQL PHP Trying to display a result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DojiWeb
Forum Newbie
Posts: 2
Joined: Fri Mar 04, 2011 3:48 am

MYSQL PHP Trying to display a result

Post by DojiWeb »

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
litebearer
Forum Contributor
Posts: 194
Joined: Sat Mar 27, 2004 5:54 am

Re: MYSQL PHP Trying to display a result

Post by litebearer »

1. where do you set the value for $zip in the form?
2. In

Code: Select all

$sql = mysql_query("select price from ID where zip =" ' %$zip%'');
Do you want the $zip variable to be an EXACT match with the table value

Code: Select all

$sql = mysql_query("select price from ID where zip = '$zip'");
OR do you want to see if it is part of the value

Code: Select all

$sql = mysql_query("select price from ID where zip LIKE '%$zip%''');
NOTE: your use of single an double quotes need to open and close properly
DojiWeb
Forum Newbie
Posts: 2
Joined: Fri Mar 04, 2011 3:48 am

Re: MYSQL PHP Trying to display a result

Post by DojiWeb »

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.
Post Reply