Help with some insert code
I have a set up that involves some insert code for a table based on a series of checkboxes, that is mixed in with some DataAssist code.
When I've used it before, the form action is another URL, with that code at the top of that page where it is executed.
But in this example, the WA form is of the form:
action="<?php echo(htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES)."?".$_SERVER["QUERY_STRING"]); ?>"
ie is reloading the page, and doing the DA insert before getting to the redirect URL in the PHP code at the top of the page.
My problem is that my other insert code is executing twice, presumably once when the page first loads, and again when the form on the page is submitted. The bit of code is this, which is the last bit of PHP before the <DOCTYPE> etc:
<?php
/********************
*
*insert Lodge Activities into the LodgeActivities table
*
********************/
//sql insert string
$sql = "INSERT INTO ItineraryActivities (ItineraryID, ActivityID) VALUES ";
$ck = $_GET['ckbox'];
//loops though the profiles adding the insert string each profile row
foreach ($ck As $GetIndex => $GetValue){
if ($GetValue=='on'){
$sql .= "('{$_GET['ItineraryID']}', '$GetIndex'), ";
}
}
//trims the end ,
$sql = rtrim($sql," ,") ;
//inserts data
mysql_select_db($database_connSafari, $connSafari); mysql_query($sql); echo mysql_error();
?>
I had thought that because my insert code is after the line with the redirect URL, it shouldn't execute on the form submit, but it looks like it is.
Hope that makes sense. I've attached a copy of the page - I'm hoping there's a fairly straightforward solution to this.
Thank you!