I recently did something very similar with my own website and received help from this community. On the HTML side I created a standard form and gave each input a "name." For example let's say you are trying to capture city and state:
<html>
<body>
<form>
<tr>
<td>State: </td><td> <input type="text" style="border:1px solid #000000" name="state" /></td>
<td>City</td><td><input type="text" style="border:1px solid #000000" name="city" /></td>
</tr>
</form>
</body>
</html>
Then set up a mySQL database with a column named "state" and one named "city". Next, use PHP to insert the data from the form into your database. I am new to PHP, but from what I understand using PDOs is more secure than using the old mysql commands.
$dbtype = "mysql";
$dbhost = "localhost";
$dbname = "name";
$dbuser = "user";
$dbpass = "pass";
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$sql = "SELECT column_name FROM information_schema.columns WHERE table_name = '[Insert Name of your table here]'";
$q = $conn->prepare($sql);
$q->execute();
$columns = $q->fetchAll(PDO::FETCH_COLUMN, 0);
$cols = array();
foreach ($_POST as $key=>$value)
{
// if a field is passed in that doesn't exist in the table, remove it. The name of the input that is removed will be echoed so you can debug. Remove echo if you go to production.
if (!in_array($key, $columns)) {
unset($_POST[$key]);
echo $key;
}
}
$cols = array_keys($_POST);
$sql = "INSERT INTO Facilities(". implode(", ", $cols) .") VALUES (:". implode(", :", $cols) .")";
$q = $conn->prepare($sql);
array_walk($_POST, "addColons");
$q->execute($_POST);
function addColons($value, &$key)
{
$key = ":{$key}";
}
This has been working out very well for me. Note that it can only match HTML form inputs with columns of the exact same name. In my case I wanted to create over 100 inputs so this was easier. If you are dealing with 5-10 it might be easier to just insert the specific variables manually.
enctype="multipart/form-data"when uploading a file. It looks like from your input fields that you're passing strings. This may be causing an issue.