Jump to content

passing drop down choice to mysql query


learningcurve

Recommended Posts

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?  :shrug:

 

<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>




Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.