learningcurve Posted May 24, 2012 Share Posted May 24, 2012 I am very, very new to Php - this is the first thing I have written. I am trying to create a very simple form with two drop downs that return the results from a mysql db in a very simplistic table format. I have this code. It works as far as making a selection goes, but then I am lost. I really don't know how to pass the selection on to the query and I feel like an idiot that is missing something obvious. Everything I read at this point is just confusing me more. It doesn't return any errors but also doesn't return any results - I know I am not passing my dropdown selections on correctly. Any help? <html> <head </head> <body> <?php $connect = mysql_connect(REDACTED); if (!$connect) { exit('<p>Unable to connect to the server at this time.</p>'); } if (!@mysql_select_db('surveys')) { exit ('<p>Unable to locate the database at this time.</p>'); } $evaluator = array("0"=>"ALL","1" =>"ALT", "2"=>"CELT","3"=>"CTL","4"=> "CTL VOA(VOA or MUM Faculty)"); $date = array("0"=>"All Dates","1"=>"Fall 2010","2"=> "Fall 2011","3"=> "Fall 2012", "4"=>"Fall 2013", "5"=>"Spring 2010", "6"=>"Spring 2011", "7"=>"Spring 2012", "8"=>"Spring 2013"); ?> <form name="sgid" id="sgid" method="post" action="sgid3.php"> <h1>Results from SGID satisfaction survey. Results can be filtered by evaluation party or semester/year given.</h1></br> Please choose: <?php echo '<select name = "Evaluator">'; foreach ($evaluator as $key=>$value){ echo '<option value =" '.$key.'"> '.$value.'</option>'; } echo '</select>'; ?> for <?php echo '<select name = "Date">'; foreach ($date as $key=>$value) { echo '<option value="'.$key.'">'.$value.'</option>'; } echo '</select>'; ?> <input type="submit" value="Show Results"> </form> <?php $sql = "SELECT * FROM SGID_satisfaction WHERE q1='Evaluator' AND q2='Date'"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)){ echo "col1 = " . $row["col1"]; echo ", col2 = " . $row["col2"] ."<br>"; } if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } mysql_free_result($result); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/263056-passing-drop-down-choice-to-mysql-query/ Share on other sites More sharing options...
Kays Posted May 24, 2012 Share Posted May 24, 2012 Where is the sgid3.php? If that is the same file, then the answer is obvious. The information is being passed to the PHP file, but you're not doing anything with them. Have a read: http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/ Quote Link to comment https://forums.phpfreaks.com/topic/263056-passing-drop-down-choice-to-mysql-query/#findComment-1348440 Share on other sites More sharing options...
learningcurve Posted June 6, 2012 Author Share Posted June 6, 2012 Thanks Kays, I have been using a variety of sources to learn and very little makes it past the fog. I have just gone through the first two lessons of this tutorial and they are pretty clear and easy. In fact, I have already made progress thanks to this blog! Quote Link to comment https://forums.phpfreaks.com/topic/263056-passing-drop-down-choice-to-mysql-query/#findComment-1351729 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.