Jaady;11037393 wrote:
I havent' put the whole page in
Having an exact copy of some version of the code and having something else is quite different. Not necessarily bad from a learning perspective, but changing things usually leads to having to change more things.
Jaady;11037393 wrote:
2- the lad in the tutorial closes the function with: // closes the database connection $dbh = NULL;
I hope that actually looked like
// closes the database connection
$dbh = NULL;
rather than what you posted. Otherwise it's a comment claiming to do stuff with no actual code being executed.
Jaady;11037393 wrote:
I have no idea where that variable come from, it doesn't show it on the tutorial
Are you certain they did not show that in an earlier example and by now assumes that you have understood that part and that you have it working?
By the way, what happens in your
Jaady;11037393 wrote:
include_once() connection to my database
and also, why is it [man]included[/man] rather than [man]required[/man]?
Jaady;11037393 wrote:
but then I;m thinking if I close the connection to the DB how am I going to get anything in my form below?
Because you first fetch what you need. Then you use whater you fetched later. The principle is the same as calling your sister and ask what she wants for her birthday. When she has told you, you hang up the phone before you go shopping.
Jaady;11037393 wrote:
and then 3- in the form the select input box has a name of [country1]
When posting a form field, the name attribute value becomes a key in the $POST array in php (or $GET in case of a get request). That is, if a form had been sent where the form field contained name="data", then there would be a corresponding entry in $POST['data']. Now it will instead reside in $POST['data']['country1'].
Jaady;11037393 wrote:
again I have no idea where that comes from
By choice. Much like your own name was once chosen.
Jaady;11037393 wrote:
and where else it is referred.
by the script receiving the post (unless of course it is a get request)
Do yourself the favor of formatting your code sensibly. What you had in your post looked as if everything belonged to the function. If I hadn't gone to the trouble of formatting it for you, I'd have simply given you error corrections based on reading it wrong. Moreover, when you are asking for help, you are far less likely to get it if you post unformatted code.
function buildOptions($array)
{
$output = '';
foreach ($array as $key => $value) {
$output .= '<option value="' . $key . '">' . $value . '</option>' . PHP_EOL;
}
return $output;
}
$list = array();
$sql = 'SELECT `id`, `building` FROM `buildings`;';
foreach ($pdo->query($sql, PDO::FETCH_ASSOC) as $row) {
$list[$row['id']] = $row['building'];
}
But where does $pdo come from?