The following dropdown is filled with data from sql database:
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
<select name="Select" id="vals" onchange="this.form.submit()" class="btn btn-warning">
<option value="">-- Select Country --</option>
<?php
$user=new User();
$sql5=DB::getInstance()->get('country', array('user', '=', $user->data()->username));
if (!$sql5->count()) {
echo 'No data';
} else {
foreach ($sql5->results() as $sql5) { ?>
<option value="<?php echo $sql5->name;?>">
<?php echo $sql5->name;?></option>';
<?php }
} ?>
</select>
</form>
</div>
And a user selects from the dropdown so that the information connecting to the selected data is outputted:
<? php
if (isset($_POST['Select']) && !empty($_POST['Select'])) {
$userSelection = $_POST['Select'];
$sql = DB::getInstance() - > get('country', array('country', '=', $userSelection));
if (!$sql - > count()) {
echo 'no data';
} else {
foreach($sql - > results() as $sql) {
echo 'data';
}
When I click an option from the dropdown, nothing comes out. The problem is with the $userSelection, a whitespace problem. When I replace the $userSelection with ' China', the data comes out but when I tried, 'China' nothing came out, it only works if there's a whitespace in front of it. I also checked my database and there's no whitespace in the values.