You can do this, but it takes alot of thought and preperation. You'll also have to give alot of thought to security. But here is a simple example of this:
<!-- HTML Form for automatic query processing -->
<form action="query.php" method="post">
<input type="hidden" name="table" value="users" />
<input type="hidden" name="cols[]" value="fname" />
<input type="hidden" name="cols[]" value="lname" />
<input type="hidden" name="constraints[]" value="ssn" />
<input type="text" name="ssn" value="" />
<input type="submit" name="submit" value="submit" />
</form>
There is a simple form with 3 hidden fields and 1 exposed field. This form will be processed by the below code:
<?php
// query.php
// query variables
$table = "";
$selCols = "";
$where = "WHERE ";
foreach ($_POST as $key => $value) {
switch ($key) {
case "table":
$table = $value;
break;
case "cols":
$selCols = implode(",", $value);
break;
case "constraints":
$sep = "";
foreach ($value as $constraint) {
$where .= $sep . $constraint . " = " . $_POST[$constraint];
$sep = "AND ";
}
break;
}
}
$query = "SELECT " . $selCols . " FROM " . $table . $where;
// Run $query and do whatever with the results.
?>
Now that is a very simple query processing structure that you control by the data that is in your forms. Personally I don't think this is a good way for you to go about building any database quering code. You are giving way too much informaiton out to the world, they will be able to know the name of your table, and the name of the columns in it, if someone wanted to they could write there own form to select everything from the table. So whatever you do don't use this code it isn't safe, it's just there to show you an example.