Jump to content

Still need help using drop downs to query MySQL


odin365

Recommended Posts

I have a page with dropdown menus that I wish to use search my MySQL database. When I try to run it, I get the head of the table, but nothing else. Thanks in advance for any help you can give me.

Here is the page of code that creates the dropdown search page:

<html>
<head>
<title>Summer Course Search</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style>
div#formError{
border: 3px;
border-color: red;
}
.fieldError {
color: red;
}

</style>
</head>

<body>

<script type="text/javascript">
function checkErrors(){
var subject = document.getElementById("Subjectsel").value;
var level = document.getElementById("Levelsel").value;
var catalog = document.getElementById("CatalogNum").value;
if ((subject != 1) && (level != 1) || (catalog != "")){
document.getElementById("searchForm").submit();
} else {
document.getElementById("formError").innerHTML = "An error has occured, please make a selection below<br><br>";
document.getElementById("subError").innerHTML = "*";
document.getElementById("levError").innerHTML = "*";
document.getElementById("catError").innerHTML = "*";

}

}

</script>
<div id="formError"></div>
<form action="test11.php" method="post" id="search">
  <p><span id="subError" class="fieldError"></span></span>
    Subject:
    <select name="Subjectsel" id="Subjectsel">
      <option value="1">-- Select --</option>
      <option value="" selected>Search All</option>
      <option value="art">ART</option>
      <option value="jor">JOR</option>
      <option value="psy">PSY</option>
    </select>
    <BR>
    <BR>
    <span id="catError" class="fieldError"></span>Catalog Number
    <INPUT TYPE=TEXT NAME= "Catalog" id="CatalogNum" SIZE=3>
    OR
    <span id="levError" class="fieldError"></span>Level:
    <select name="Levelsel" id="Levelsel">
      <option value="1">-- Select --</option>
      <option value="" selected>Search All</option>
      <option value="100">100</option>
      <option value="200">200</option>
      <option value="300">300</option>
    </select>
  </p>
  <p><span id="sessError" class="fieldError"></span>Session:
    <select name="Sessionsel" id="Sessionsel">
      <option value="1">-- Select --</option>
      <option value="" selected>Search All</option>
      <option value="ss1">SS1</option>
      <option value="ss2">SS2</option>
      <option value="ss3">SS3</option>
      <option value="alt">ALT</option>
    </select>
    </p>
    <span id="startError" class="fieldError"></span></p>
  <p>Start:
    <select name="Startsel" id="Startsel">
      <option value="1">-- Select --</option>
      <option value="" selected>Search All</option>
      <option value="8:00 AM">8:00 AM</option>
      <option value="10:00 AM">10:00 AM</option>
      <option value="12:00 PM">12: 00 PM</option>
      <option value="4:00 PM">4:00 PM</option>
      <option value="6:00 PM">6:00 PM</option>
      <option value="TBA">TBA</option>
    </select>
    </p>
    </p>
  <p><span id="dayError" class="fieldError"></span>Day:
    <select name="Daysel" id="Daysel">
      <option value="1" selected>-- Select --</option>
      <option value="">Search All</option>
      <option value="MW">MW</option>
      <option value="M-TH">M-TH</option>
      <option value="TTH">TTH</option>
      <option value="TBA">TBA</option>
    </select>
    </p>
    <span id="locError" class="fieldError"></span></p>
  <p>Location:
          <select name="Locationsel" id="Locationsel">
            <option value="1">-- Select --</option>
            <option value="" selected>Search All</option>
            <option value="KING">KING</option>
            <option value="PROV">PROV</option>
            <option value="ON LINE">ON LINE</option>
          </select>
    </p>
  </p>
  <p>Gen Ed: (check one)
<input type="radio" name="GenEd" value="1"> Yes
<input type="radio" name="GenEd" value="0"> No
<input type="radio" name="GenEd" value="all" checked> All classes

</p>
<p>Freshman Friendly: (check)
<input type="radio" name="Fresh" value="1"> Yes
<input type="radio" name="Fresh" value="0"> No
<input type="radio" name="Fresh" value="all" checked> All classes

</p>

<p>
  <!--<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="SEARCH"><BR><BR>-->
  <input type="submit" name="search" value="search" onClick="checkErrors()">
  </p>
<p>
  <INPUT TYPE="RESET" NAME="RESET" VALUE="Reset">
 
</p>
</form>
</body>
</html>







*********HERE IS MY PAGE TO (Supposedly) RETURN THE RESULTS****************



<html><head>
<title>Search for Summer Course</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
div#searchresult {margin-top: 100px;}
table#result_table {position:relative;text-align:center;vertical-align:center;margin-right: auto;margin-left:auto;padding:0;}
table#result_table td {text-align: center;font:10px Verdana, Arial, Helvetica, sans-serif;padding:1em;color: #06F;border: 1px solid grey;}
table#result_table th {text-align:center;font: bolder 14px Verdana, Arial, Helvetica, sans-serif;
padding:1.25em;color: #006;background-color: #9CF;}
.style1 {font-size: 10px}
</style>
</head><body>
<div id="searchresult">
<?php
//connect to mysql database -- coursetest table
include ('../connect.php');
$search=$_POST['Subjectsel'];

$result = mysql_query("SELECT * FROM coursum WHERE subject LIKE '%$search%' ORDER BY subject") or die(mysql_error());
//result table
?>
<table id="result_table" border=0>
<tr><th><span class="style1">Subject</span></th><th><span class="style1">Catalog</span></th><th><span class="style1">Description</span></th><th><span class="style1">Instructor</span></th><th><span class="style1">Section</span></th><th><span class="style1">Units</span></th><th><span class="style1">Session</span></th><th><span class="style1">Start</span></th><th><span class="style1">Day</span></th><th><span class="style1">Location</span></th><th><span class="style1">Notes</span></th>
</tr>
<?php
while($r=mysql_fetch_array($result))
{
  //the format is $variable = $r["nameofmysqlcolumn"];
  //modify these to match your mysql table columns 
  $subject=$r["subject"];
  $catalog=$r["catalog"];
  $instructor=$r["instructor_last"];
  $start=$r["start"];
  $end=$r["end"];
  $location=$r["location"];
  $session=$r["session"];
  $section=$r["section"];
  $units=$r["units"];
  $notes=$r["notes"];
  $description=$r["description"];
  $gen_ed=$r["gen_ed"];
 
  //display the row
?>

<tr><td>

<?php $subject?></td><td><?php $catalog?></td><td><?php $description?></td><td><?php $instructor?></td><td><?php $section?></td><td><?php $units?></td><td><?php $session?></td>  <td><?php $start - $end?></td><td><?php $day?></td><td><?php $location?></td><td><?php $notes?></td>
</tr>
<?php
};
?>
</table>
</div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.