close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues


Conditional Redirect in Update Statement

Thread began 2/04/2011 8:30 am by bjgarner241692 | Last modified 2/04/2011 11:34 am by Jason Byrnes | 1242 views | 8 replies |


Conditional Redirect in Update Statement

I've borrowed from DataAssist in order to update a customer record.
In DA, the Redirect URL would be the detail page of the record. I changed that to go to a page with a form and that worked just fine, but now I am trying to fine tune it because depending on the visit number, the client will get a different form.

Once I put in the conditional statement though, it seems to ignore it and instead defaults to the form appropriate for visit 1, even though my visitcount is being properly updated.

Here is my Update code.


// WA Application Builder Update
if (($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)) // Trigger
$WA_connection $conn;
$WA_table "clienttable";
  if (
$row_count['visitcount'] <= 1) { // Adv Conditional Region
$WA_redirectURL "https://____/index.php?option=com_content&view=category&layout=blog&id=10&Itemid=38";
// $row_count['visitcount'] <= 1
if ($row_count['visitcount'] >=2) { // Adv Conditional Region
$WA_redirectURL "https://_____/index.php?option=com_content&view=category&layout=blog&id=23&Itemid=60";
// $row_count['visitcount'] >=2
$WA_keepQueryString false;
$WA_indexField "eID";
$WA_fieldNamesStr "emailaddr|visitcount|username|fname|lname";
$WA_fieldValuesStr "".((isset($_POST["emailaddr"]))?$_POST["emailaddr"]:"")  ."" "|" "".((isset($_POST["visitcount"]))?$_POST["visitcount"]:"")  ."" "|" "".((isset($_POST["username"]))?$_POST["username"]:"")  ."" "|" "".((isset($_POST["fname"]))?$_POST["fname"]:"")  ."" "|" "".((isset($_POST["lname"]))?$_POST["lname"]:"")  ."";
$WA_columnTypesStr "',none,''|none,none,NULL|',none,''|',none,''|',none,''";
$WA_comparisonStr "=|=|=|=|=";
$WA_fieldNames explode("|"$WA_fieldNamesStr);
$WA_fieldValues explode("|"$WA_fieldValuesStr);
$WA_columns explode("|"$WA_columnTypesStr);
$WA_where_fieldValuesStr "".((isset($_POST["WADAUpdateRecordID"]))?$_POST["WADAUpdateRecordID"]:"")  ."";
$WA_where_columnTypesStr "none,none,NULL";
$WA_where_comparisonStr "=";
$WA_where_fieldNames explode("|"$WA_indexField);
$WA_where_fieldValues explode("|"$WA_where_fieldValuesStr);
$WA_where_columns explode("|"$WA_where_columnTypesStr);
$WA_where_comparisons explode("|"$WA_where_comparisonStr);
$WA_connectionDB $database_conn;
  if (!
session_id()) session_start();
$updateParamsObj WA_AB_generateInsertParams($WA_fieldNames$WA_columns$WA_fieldValues, -1);
$WhereObj WA_AB_generateWhereClause($WA_where_fieldNames$WA_where_columns$WA_where_fieldValues,  $WA_where_comparisons );
$WA_Sql "UPDATE `" $WA_table "` SET " $updateParamsObj->WA_setValues " WHERE " $WhereObj->sqlWhereClause "";
$MM_editCmd mysql_query($WA_Sql$WA_connection) or die(mysql_error());
  if (
$WA_redirectURL != "")  {
    if (
$WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL'?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
header("Location: ".$WA_redirectURL);

I am sure it is just syntax, or ordering, but I am struggling. Any insight or assistance would be greatly appreciated.


Sign in to reply to this post

Jason ByrnesWebAssist

This update behavior is setting the visit count right?

the recordset does not have any visibility to what the updated value will be, the recordset is created before the visit count is updated.

i see in the update code, you are setting the visit count using the visit count form element:

are you doing the increment in the visit count form elements value?

if so, this form element is what should be used in your if statement, not the recordset value.

Sign in to reply to this post


hmm, but I want the present value, before update, to determine which form to show.

Actually, that part works perfectly. If I remove the conditional statements and just load one page or the other, it increments the visitcount properly and it forwards the visitor.

I actually had it like that initially and on the next page I had the if / then showing the appropriate form in an <iframe> but that approach is not ideal.

So here is what I am trying to do.
Load page
check how many visits have been made to date
Select appropriate redirect URL
Process Record Update, incrementing visitcount by 1, (for next visit)
Process redirect URL

Sign in to reply to this post

Jason ByrnesWebAssist

Ok, It sounded like you wanted to use the new updated value.

it would be helpful to have the entire page rather than just the update record code so I could see how the form action is set as well as the recordset.

I have a feeling the recordset is set to filter on a querystring variable that is not included as a part of the form action.

If that is the case, the url variable needs to be included with the form action:
action="updatepage?id=<?php echo(isset($_GET['id'])?$_GET['id']:""); ?>"

Sign in to reply to this post


Thanks Jason,
Actually, I took your first suggestion and changed the conditional statement to use the form value.
The form processed properly. I think I just need to fine tune the < or >.
If that does not yield the expected result I will look at your latest suggestion.

I appreciate your help.

Sign in to reply to this post


nope, same issue whether I use rs or post.
I thought maybe it was an order of operations thing so I moved the redirect code down, after the post info but it makes no difference.

My count increments, but I cannot make it display the page appropriate to those visitors who are at 2 or higher.

zip attached.

Attached Files
Sign in to reply to this post

Jason ByrnesWebAssist

your if statement uses a recordset that does not exist on the page.

in your if statement, you are using a recordset named count;
if ($row_count['visitcount'] <= 1) { // Adv Conditional Region

no such recordset is defined on the page, you do have a recordset named WADAclienttable, try using that instead:

if ($row_WADAclienttable['visitcount'] <= 1) { // Adv Conditional Region

Sign in to reply to this post


Nice catch - I'm guilt of copying that if statement from another page and not changing the rs name.

Works perfectly now - go figure!

Thank you again. It is great to have a second set of eyes with this stuff.

I want to share something else I did on this page that I think would serve others as well.

I cannot have people coming BACK to this page, becuase it will trigger the visit count, so I added another counter, based on session values.


$_SESSION['views'] = $_SESSION['views']+ 1;
$_SESSION['views'] = 1;

Then, I wrapped the FORM tags with

<?php if ($_SESSION['views'] == 1) { // Adv Conditional Region ?>

... form stuff ....

  <?php // $_SESSION['views'] == 1 ?>

Works perfectly and is a much simpler way of preventing the inadvertent post of data than anything else I could find online.

If someone backs out of the confirmation page, they just see a blank page (with navigation) when they get back to this counting page, and since there is no form, there is no update.

Sign in to reply to this post

Jason ByrnesWebAssist

OK, glad it is working.

when reporting problems like this it is very helpful to post the entire page rather than a piece of the code.

I could have spotted the recordset issue on the first reply if I had the entire page to start with.

Sign in to reply to this post

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





Ease of use


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...