I am trying to pass some php via a dropdown in html , the php then needs to be used to aid the execution of more php. However I do not think it is working. Any suggestions would really be appreciated, its been bugging me a while. This is not the first form to use post on this page, the dropdown is populated after a search has been performed using another previous form.
HTML:
<form method="post" name="results">
<select class="form-control textinput">
<option value="<?php $response->body->results[0]?>"><?php echo $response->body->results[0]->name; ?></option>
<option value="<?php $response->body->results[1]?>"><?php echo $response->body->results[1]->name; ?></option>
<option value="<?php $response->body->results[2]?>"><?php echo $response->body->results[2]->name; ?></option>
<option value="<?php $response->body->results[3]?>"><?php echo $response->body->results[3]->name; ?></option>
<option value="<?php $response->body->results[4]?>"><?php echo $response->body->results[4]->name; ?></option>
</select>
<button type="submit" class="btn btn-primary" style="margin-left: auto; margin-right: auto; text-align: center;">Go</button>
</form>
PHP:
<?php
//Results from dropdown are put into selection
$selection = $_POST["results"];
//Selection is put into result var, should look like $response->body->results[x]
$result = $selection;
// IF Statement to only print result if the api call is successfull
if ($response->code == 200) {
if ($result->name == null) {
$printthis = "{$gametitle} returned no results, try and enter the full and accurate name";
}
else {
$printthis = "{$result->name} has a score of {$result->score} on {$result->platform}";
}
}
?>
First, you missed the 'echo' statement, and you also can't put an entire object into a value. If
has an id, thats what you should be using
something like this
I would do this with a loop.