I have a problem when I pass a value to a function that is post into the document in PHP
This is the function definition,
function findstation($val){
global $positions_table;
var_dump($val);
$id=$val;
$query = array('uid'=> $id );
$result = $positions_table->find($query);
foreach ($result as $station){
return $station['name'];
}
}
This function queries a mongoDB database to find and return the key name from the DB
I have page which posts the id into the document as $_POST['id'].
This is how I search in it
if(isset($_POST['submit'])){
echo "START!";
$st = $_POST['station'];
var_dump($t);
findstation($st);
echo "EXECUTED THE FUNCTION"; // Just added this to diagnose
}
When I search like this, i don’t get any results it just displays START!EXECUTED THE FUNCTION
But when i call the function like this
findstation(2);
I get a result. How can I get this to work when I pass it as a varible ?
PS: $_POST['id'] is passed as value of a <select> input.
Correct: