I created radiobuttons dynamically based on my Categories Table and 'catdesc' column.
For all parts of form that have a name that equals Categories.catdesc I want to insert the Name and Value into a new table called "Test". From what you gave me, I have come up with this, however it is not working, I do not think I have the condition correct. So far it inserts one row of zeros into the Test table.
Here is the dynamic insertion PHP:
Code: Select all
$result = mysql_query("SELECT * FROM Categories ORDER BY catdesc");
while ($array = mysql_fetch_array($result)) {
echo '<table border="1">
<tr>
<td width = "36%">
<b>'.$array['catdesc'].'</ b>
</td>
<td width = "16%" align=center>
<INPUT TYPE="radio" NAME="name['.$array['catdesc'].']" VALUE="0" checked>
<font size="2">None</font>
</td>
<td width = "16%" align=center>
<INPUT TYPE="radio" NAME="name['.$array['catdesc'].']" VALUE="1">
<font size="2">Mild</font>
</td>
<td width = "16%" align=center>
<INPUT TYPE="radio" NAME="name['.$array['catdesc'].']" VALUE="2">
<font size="2">Med.</font>
</td>
<td width = "16%" align=center>
<INPUT TYPE="radio" NAME="name['.$array['catdesc'].']" VALUE="3">
<font size="2">Strong</font>
</td>
</tr>
</table>';
}
Here is my attempt at moving the all all data even "0" into the database:
Code: Select all
$conditions = array();
foreach ((array)$_POST["name"] as $name) {
$conditions[] = "`Categories.catdesc` = '" . mysql_real_escape_string($name) . "'";
}
$query = "SELECT * FROM Categories";
if ($conditions) $query .= " WHERE " . implode(" AND ", $conditions);
$sql2 = "INSERT INTO Test (Variable)
VALUES
('$name')";
if (!mysql_query($sql2,$con))
{
die('Error: ' . mysql_error());
}