SirRichiVanPiimp Posted June 5, 2013 Share Posted June 5, 2013 Hi guys, Newbie to the forums here.... i have just started out using PHP to develop websites and I am having a little problem getting formation from a database. What I am looking to do is, using a form I want to get data from a DB called events depending on variables i.e.location, time or event. So, if the user selects the location on the form - say America - I want to be able to display form data only with the events in America. So, its like .. .Form data (location) -- form listing (only events from chosen location) I have managed to get a form to populate the database, I can retrieve ALL the form data using a recordset, but I unable to retrieve and display the data, nor am I able to locate a tutorial for this... Any help would be GREATLY APPRECIATED!!!!! Richie Link to comment https://forums.phpfreaks.com/topic/278815-database-information-retrieved-using-form-values-using-php/ Share on other sites More sharing options...
SirRichiVanPiimp Posted June 5, 2013 Author Share Posted June 5, 2013 Oh, if it helps.. I am using PHP, MySQL & my localhost is run via myPHPadmin Thanks again Link to comment https://forums.phpfreaks.com/topic/278815-database-information-retrieved-using-form-values-using-php/#findComment-1434285 Share on other sites More sharing options...
litebearer Posted June 5, 2013 Share Posted June 5, 2013 1. check here - http://www.tizag.com/mysqlTutorial/mysqlwhere.php 2. show us what you have tried thus far, and tell us where you are experiencing the problems/errors Link to comment https://forums.phpfreaks.com/topic/278815-database-information-retrieved-using-form-values-using-php/#findComment-1434290 Share on other sites More sharing options...
SirRichiVanPiimp Posted June 5, 2013 Author Share Posted June 5, 2013 Hi LittleBearer ... thanks so much for your help there... this is what I have so far... if(Search){ mysql_connect("localhost", "root" , "root") or die (mysql_error()); echo "Connected to MySQL <br/> <hr/>"; mysql_select_db("users")or die (mysql_error()); echo "conncted to DB users <br/> <hr/>"; $query = "SELECT * FROM events"; $result = mysql_query($query) or die (mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['EventName'] . "-" . $row['location']; echo "<br />"; } } else echo " Found nothing"; ?> <form action="SearchTest.php" method="get" id="Search"> <select name="location"> <option value="sligo">sligo</option> <option value="galway">galway</option> </select> <input name="submit" type="button" value="submit" /> </form> Results are as follows:Connected to MySQL conncted to DB users 1111-sligo1111ccc-galwayDundalk 10K run-Fun Run for all -Richie-run4444-Run4Fun-hhhgggggggggggg-dublinRunningzzzzz-dublin sligo galway Using the website you gave me, I have altered the code to: <?php // Make a MySQL Connection mysql_connect("localhost", "root", "root") or die(mysql_error()); mysql_select_db("users") or die(mysql_error()); echo "connected....."; // Get a specific result from the "example" table $result = mysql_query("SELECT * FROM events WHERE location ='galway'") or die(mysql_error()); // get the first (and hopefully only) entry from the result $row = mysql_fetch_array( $result ); // Print out the contents of each row into a table echo $row['location']." - ".$row['EventName']; ?> this displays the first result..... Thanks again Link to comment https://forums.phpfreaks.com/topic/278815-database-information-retrieved-using-form-values-using-php/#findComment-1434293 Share on other sites More sharing options...
SirRichiVanPiimp Posted June 5, 2013 Author Share Posted June 5, 2013 I have got this far, if anyone would like to add assistance: $location = $_POST['location']; if(LocationForm){ mysql_connect("localhost", "root" , "root") or die (mysql_error()); echo "Connected to MySQL <br/> <hr/>"; mysql_select_db("users")or die (mysql_error()); echo "conncted to DB users <br/> <hr/>"; $query = "SELECT * FROM events Where location = '$location'"; $result = mysql_query($query) or die (mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['EventName'] . "-" . $row['location']; echo "<br />"; } } else echo "nothing"; ?> <form action="SearchTest.php" method="$_POST['location']" id="LocationForm"> <select name="location"> <option value="sligo">sligo</option> <option value="galway">galway</option> </select> <input name="submit" type="button" value="submit" /> </form> Which returns a blank value as the form is not inputting a value. If I manually input a value for location I can get the required results.As, I said, I would appreciate any help here...;o)) Link to comment https://forums.phpfreaks.com/topic/278815-database-information-retrieved-using-form-values-using-php/#findComment-1434306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.