
Originally Posted by
gpigate
you are correct on the if, the structure is right... I may have been looking out of only 1 eye before
I placed the code you have above in a small test.php file and I am able to echo out test statements so I think your code is syntactically ok.
any chance you can put the whole script up? url to the page?
Thanks for the help.
The form is very dynamic and so I think the whole script wouldn't be very helpful. I found an error I had and have made some changes to the original code. If a solution isn't apparent after this, I will do my best to add some details to the code and post the rest of the script.

Originally Posted by
gpigate
also is that your entire post or submit section once the form is submitted? no header redirect or output of anything?
After insert it should redirect. Here is the new code along with the redirect.
PHP Code:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
{
foreach ($_POST as $var => $value)
{
if ($value != NULL)
{
$combinedID = explode("-",$var));
// $var is the input name, for text inputs the name is questions_ID followed by a dash followed by options_ID so we must split them apart to get the values. Example $var is 10-101 for text inputs
if ($combinedID[1] != "" && $combinedID[1] != NULL)
{
$insertSQL = "INSERT INTO response (request_ID, questions_ID, options_ID, details, customer_ID) VALUES ('".mysql_real_escape_string($_POST['rid'])."', '".(int)$combinedID[0]."', '".(int)$combinedID[1]."','".$value."','".mysql_real_escape_string($_POST['cid'])."')";
}
else
// $var is the input name, $value is the input value, for radio inputs the name is the questions_ID and the value is the options_ID, radio inputs have no details. Example $var is 10, $value is 101 for radio inputs
{
$insertSQL = "INSERT INTO response (request_ID, questions_ID, options_ID, details, customer_ID) VALUES ('".mysql_real_escape_string($_POST['rid'])."', '".(int)$var."', '".(int)$value."','".NULL."','".mysql_real_escape_string($_POST['cid'])."')";
}
mysql_select_db($database_connDBName, $connDB);
$Result1 = mysql_query($insertSQL, $connDB) or die(mysql_error());
}
}
}
$insertGoTo = "thanks.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
header(sprintf("Location: %s", $insertGoTo));
Bookmarks