I have a form in HTML5 on a PHP page. Some of the form elements contain PHP code for things such as populating a drop-down menu with options. Different options are put in each menu, but they all are populated by the same PHP code (called query.php).
I want to pass the name of the HTML element to query.php to determine which query to execute. query.php is coded generally:
<?php
$connection = pg_connect(...);
$query = "SELECT name FROM table ORDER BY name ASC;";
$results = pg_query($connection, $query);
$rows = pg_num_rows($results);
for ($i=0; $i < $rows; $i++) {
?>
<option><?php echo pg_fetch_result($results, $i, 0); ?></option>
<?php
}
?>
I want 'table' in $query to be a variable coming from the HTML. Here is an example line of HTML:
<p>Select a City: <select name="city"><?php include("query.php"); ?></select>
I've been trying to use the HTTP GET method replacing 'query.php' with query.php?table=$this.name. I understand that I should be able to use $_GET['table'] in query.php and get the passed value, but I don't know the function to get the name of the HTML element. What function, when used within HTML tags, will return the name of the HTML element? For example, if I use query.php?table=$this.name in the above HTML, $_GET['table'] in query.php should return "city". Only $this.name is not the correct function.