I have a form consisting of a select input dropdown. The dropdown is populated from a SQL query. Here is the relevant code:
<form action="process.php" id="journals_tally" method="post">
<select>
<?php
$result = mysqli_query($link, "SELECT jid,title from journals_cancel_15 ORDER by title");
$num = mysqli_num_rows($result);
for ($i=0; $i<$num; $i++) {
$row = mysqli_fetch_assoc($result);
echo "<option value=\"$row[jid]\" name=\"jid\">$row[title]</option>";
}
?>
</select>
<input type="submit" value="Submit tally" />
</form>
The intention is for a staff person to select a title and for the form to pass the jid to a data table. The process.php page consists of the following code:
<?php
if (isset($_POST['jid'])
{
$jid = mysqli_real_escape_string($link, $_POST['jid']);
$sql = 'INSERT into journals_cancel_15_tally2(jid)
VALUES("' . $jid . '")';
if (!mysqli_query($link, $sql))
{
$error = 'Error adding submitted journal details: ' . mysqli_error($link);
include 'error.html.php';
exit();
}
header('Location: journals2015-tallying2.php');
exit();
}
?>
As you can see, all I am trying to do is to insert the jid for the record each time the form is submitted but it’s not getting inserted into the table. When I have the data type for jid set as a VARCHAR, a new row is inserted but the jid remains blank. When I have the data type for jid set as INT an error is thrown. I have tried to var_dump() the fields but nothing displays. I am certain that I’ve missed something obvious but it’s escaping me. What am I missing in the scripts above? Thanks!