Question about after loading the second listbox options
Posted: Fri Jan 15, 2016 10:54 am
Hi, I am new to PHP and am developing a site with two list boxes. Both list options are loaded from MySQL tables. I can get the second list loaded after an option is selected from the first list. However, when I try to use the selected option from the second list to retrieve the record from MySQL, the selected option doesn't seem to be captured, thus I have nothing to pass onto the database. Thanks a lot in advance!
Here's my codes.
Here's my codes.
Code: Select all
// Load Country list from the Database to the list
$sql = "SELECT * FROM country ORDER BY name";
$query = mysqli_query($dbCon, $sql);
While ($row = mysqli_fetch_array($query)){
$scountry=$row[1]. " - " . $row[0];
$option_block .= '<option value="'.$scountry.'">'.$scountry.'</option>';
}
// Check selected Country
if (isset($_POST['aftercountrysummit']))
{
$vcountry = secure_input($dbCon, $_POST['scountry']);
if ($vcountry == " - - Please Select")
{
echo "Please select from the Country list!";
} else {
// Load the Institution List
$sql = "SELECT * FROM partner WHERE Country = '$vcountry'";
$query = mysqli_query($dbCon, $sql);
$recordcount = mysqli_num_rows($query);
if ($recordcount>0)
{
echo "<br>Total number of institution partners in ".$vcountry." is ".$recordcount. "<br>";
While ($row = mysqli_fetch_assoc($query))
{
$spartner=$row["Institution_Name"];
$institution_block .= '<option value="'.$spartner.'">'.$spartner.'</option>';;
}
} else {
echo "No institution partners in ". $vcountry;
}
}
}
// Check selected Institution
if (isset($_POST['searchrecord']))
{
$vinstitutionname = secure_input($dbCon, isset($_POST['spartner']));
if ($vinstitutionname != "")
{
//Load the selected Institution details
$sql = "SELECT * FROM partner WHERE Institution_Name = '$vinstitutionname'";
$query = mysqli_query($dbCon, $sql);
$recordcount = mysqli_num_rows($query);
echo "<br>Total number of records is ".$recordcount." Institution CODE is ". $row["Institution_Code"];
if ($recordcount>0)
{
echo "Details: ".$row;
}
} else {
echo "<br> NO RECORDS!";
}
}
// Load Institution list from the Database after the Country is selected
?>
</head>
<body>
<form name="searchcountry" id="searchcountry" method="post" action="<?PHP echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<label for="selectcountry">Country:</label>
<select name="scountry" id="scountry"><?php echo "$option_block"; ?></select>
<input type="submit" name="aftercountrysummit" id="aftercountrysubmit" value="Next">
</form>
<form name="searchinstitution" id="searchinstitution" method="post" action="<?PHP echo htmlspecialchars($_SERVER['PHP_SELF']); ?>">
<label for="selectinstitution">Institution:</label>
<select name="spartner" id="spartner" onChange="getDetails(this.value)" ><?php echo "$institution_block"; ?></select>
<input type="submit" name="searchrecord" id="searchrecord" value="Search">
</form>