jgifford
01-12-2009, 08:18 PM
I've created a Database schema that will allow the admin to easily update thier form. To do this I am using the data from the DB to dynamically create the form. For example, if the admin wants to add a new input to the form, they can do that by giving it a name and a type, such as text or radio.
I've written code that displays the form based on the data. I'm stuck on getting the results from the form inserted back to the DB. Hopefully I can explain this well enough without having to post all the details.
I have one table that is the responses from the form. Each row contains 5 columns that represent the request, the question, the option chosen, any details from the option chosen (text from a text field) and a customer id.
I need to do an insert that will create a new row for the user's response to each question. I'm having some difficulty creating this mutiple row insert. Here is what I have so far. I'm hoping it's just a syntax issue...but it could be more. Thanks in advance.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
foreach ($_POST as $var => $value)
{
if ($value != NULL)
{
$insertSQL = sprintf("INSERT INTO response (request_ID, questions_ID, options_ID, details, customer_ID) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['rid'], "int"),
GetSQLValueString($var, "int"),
GetSQLValueString($value, "int"),
GetSQLValueString($value, "text"),
GetSQLValueString($_POST['cid'], "int"));
mysql_select_db($database_connDBName, $connDB);
$Result1 = mysql_query($insertSQL, $connDB) or die(mysql_error());
}
}
}
I've written code that displays the form based on the data. I'm stuck on getting the results from the form inserted back to the DB. Hopefully I can explain this well enough without having to post all the details.
I have one table that is the responses from the form. Each row contains 5 columns that represent the request, the question, the option chosen, any details from the option chosen (text from a text field) and a customer id.
I need to do an insert that will create a new row for the user's response to each question. I'm having some difficulty creating this mutiple row insert. Here is what I have so far. I'm hoping it's just a syntax issue...but it could be more. Thanks in advance.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
foreach ($_POST as $var => $value)
{
if ($value != NULL)
{
$insertSQL = sprintf("INSERT INTO response (request_ID, questions_ID, options_ID, details, customer_ID) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['rid'], "int"),
GetSQLValueString($var, "int"),
GetSQLValueString($value, "int"),
GetSQLValueString($value, "text"),
GetSQLValueString($_POST['cid'], "int"));
mysql_select_db($database_connDBName, $connDB);
$Result1 = mysql_query($insertSQL, $connDB) or die(mysql_error());
}
}
}