fishswim Posted March 24, 2014 Share Posted March 24, 2014 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> '; ?> Link to comment Share on other sites More sharing options...
HartleySan Posted March 25, 2014 Share Posted March 25, 2014 Two things I would try: Using the MySQLi (notice the i) family of functions instead of the MySQL family of functions. The MySQL family of functions are now pretty out of date. Trying the following query on the DB directly, and seeing if it works: SELECT biz_name FROM retail_client WHERE zip_code = 99201; Please let us know what happens after you try those two things. Thanks. 1 Link to comment Share on other sites More sharing options...
fishswim Posted April 6, 2014 Author Share Posted April 6, 2014 Yes with a large exclamation mark. Migrating with the bison. yet i am a little slow. i was really freaking out on that script. it has been two years since i was fully into coding, been working the graveyard shift, learned my lesson. this works also, WHERE column_name = REGEXP ' '; Thanks for the reply. Link to comment Share on other sites More sharing options...
HartleySan Posted April 6, 2014 Share Posted April 6, 2014 Glad it worked. Just FYI though: Regexes are pretty slow, so try to avoid them when you can. Link to comment Share on other sites More sharing options...
Thorcoft Posted April 25, 2016 Share Posted April 25, 2016 You can use the PHP fputcsv function to generate CSV files from array. The array can be created via mysql_query and mysql_fetch_assoc functions. If you need more help, let me know. Link to comment Share on other sites More sharing options...
IvanQawo Posted October 22, 2017 Share Posted October 22, 2017 Now we all know this sort of query to get some simple from the Database: includeconnect.php; query = "SELECT FROM table WHERE name = Apache"; result = mysql_queryquery; whilerow = mysql_fetch_assocresult echo rowname; NOw this is a great way, but imagin you had 20 pieces of data, and dont want to write row every time. Well here the solution includeconnect.php; query = "SELECT FROM table WHERE name = Apache"; result = mysql_queryquery; whilerow = mysql_fetch_assocresult extractrow; echo name; This simple line of code pulls the row out of the variablkes, so now you can call on them using the name of the mysql row, without that nasty row Link to comment Share on other sites More sharing options...
Recommended Posts