close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Help with some insert code

Thread began 5/17/2013 2:38 pm by iainmacdonald331081 | Last modified 5/20/2013 8:55 pm by iainmacdonald331081 | 665 views | 13 replies |

iainmacdonald331081

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!

Sign in to reply to this post

Jason ByrnesWebAssist

what is the path to the page on the server?

it looks like the redirect is set to reload the page:
$WA_redirectURL = "../itinerary_added/";


there is no if statement around the insert, so it will occur any time the page is loaded.

Sign in to reply to this post

iainmacdonald331081

Sorry - because I've used index.php as the file names with the folders showing in the URL, the page I attached is itinerary_add_images/index.php, which redirects to itinerary_added/index.php.

Basically what I would like to happen on the page I attached is for the code:

<?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();
?>

To only execute when it is first loaded, and not execute a second time when the form is submitted. If that can be achieved using an IF statement that would be great, although I'll need a hand with the syntax for that.

Sign in to reply to this post

Jason ByrnesWebAssist

use an if statement to check the query string:
<?php if(isset($_GET['ckbox']) && $_GET['ckbox'] != "") { ?>
insert code here
<?php } ?>

and change the forms action:
action="<?php echo(htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES)."?".$_SERVER["QUERY_STRING"]); ?>"

to:
action="<?php echo(htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES)."?".(isset($_GET['ItineraryID'])?"ItineraryId=".$_GET['ItineraryID']:""); ?>"

Sign in to reply to this post

iainmacdonald331081

Thanks Jason.

Can you check the action line, as its throwing up a PHP error in DW.

Have attached a revised copy in case I missed something.

Sign in to reply to this post

CraigRBeta Tester

try adding an extra ')' on the end of the string, so that they balance out

action="<?php echo(htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES)."?".(isset($_GET['ItineraryID'])?"ItineraryId=".$_GET['ItineraryID']:"")); ?>"

Sign in to reply to this post

iainmacdonald331081

Thanks Craig - I did look for anything like that, but missed it for looking.

Unfortunately I still have the original problem, with that insert code executing twice.

Sign in to reply to this post

Jason ByrnesWebAssist

I'll need to troubleshoot directly, see the private message section.

Sign in to reply to this post

iainmacdonald331081

Thanks Jason - details below.

Sign in to reply to this post

iainmacdonald331081

Just to say the server looks like its back up now.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...