I am working with PHP Third edition and MySQL second edition - both show php mysql scripts.
working with PHP for the web, third edition, page 373, modify the script to accept value from form field
and then and to receive data from database.
I have re worked this many times over and am frustrated to the point of brain freeze.
what can i do to receive the business name associated with zip code in database.
any assistance ? thank you.
<?php
if ( isset($_POST['submitted']) ) {
$baz = $_POST['zip'];
$dbc = mysql_connect('localhost', 'usr_name', 'password');
mysql_select_db('data_base_name');
//$query = 'SELECT biz_name FROM retail_client WHERE zip_code = 99201';
//$query = 'SELECT biz_name FROM retail_client WHERE zip_code = \'$baz\' ';
// error message: mysql_query() expects parameter 2 to be resource,
if($r = mysql_query('$dbc' 'SELECT biz_name FROM retail_client WHERE zip_code = 99201')) {
while ($row = mysql_fetch_array($r) {
print "<p> {$row['biz_name']} </p>";
} // while
} // two
} //ONE
print ' <form action="this_script.php" method="post">
<p>Zip code:
<input type="text" name="zip" size="10" /></p>
<input type="submit" name="submit" value="go" />
<input type="hidden" name="submitted" value="true" />
</form> ';
?>