close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Count searches by logged in user

Thread began 3/06/2017 5:39 pm by bjgarner241692 | Last modified 3/07/2017 1:11 pm by Ray Borduin | 339 views | 6 replies |

bjgarner241692

Count searches by logged in user

I need to count each time someone uses a search form.
To update the data, I am using:

php:
$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["button2"])) && ($_POST["button2"] == "form2")) {
      $updateSQL = sprintf("UPDATE members SET currentcount = currentcount + '1' WHERE mID=%s",
                       GetSQLValueString($_POST['nothing'], "int"),
                       GetSQLValueString($_POST['mID'], "int"));

  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());

  $updateGoTo = "search-result.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}



Unfortunately, not only am I not counting the search, but the search form does not load the results page so I assume it is a triggering problem, but I have not been able to find a working trigger.

If I change the form post from <?php echo $editFormAction; ?> to the actual results page address the search produces the correct result, but if I do that I have no way of triggering the count. I have tried putting the count on the next page but that did not work either.

How can I trigger this count AND submit the search?

Sign in to reply to this post

Ray BorduinWebAssist

Add the count code to the results page instead of the search page and then set the form action to the results page.

Sign in to reply to this post

bjgarner241692

So I did that and of course the search works, but I the count does not update.

php:
/* count */

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["button2"])) && ($_POST["button2"] == "form2")) {
      $updateSQL = sprintf("UPDATE members SET currentcount = currentcount + '1' WHERE mID=%s",
                       GetSQLValueString($_POST['nothing'], "int"),
                       GetSQLValueString($_POST['mID'], "int"));

  mysql_select_db($database_conn, $conn);
  $Result1 = mysql_query($updateSQL, $conn) or die(mysql_error());

  $updateGoTo = "";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
/* end count */



also tried using WADBSearch1 as the target to no avail.
Considered and tried a trigger of if ""="". It did not work, but even if it had it would be less than ideal because it would count on a page refresh and probably clicking from page to page of results as well.

Sign in to reply to this post

Ray BorduinWebAssist

I think this:
$updateSQL = sprintf("UPDATE members SET currentcount = currentcount + '1' WHERE mID=%s",
GetSQLValueString($_POST['nothing'], "int"),
GetSQLValueString($_POST['mID'], "int"));

should be:
$updateSQL = sprintf("UPDATE members SET currentcount = currentcount + '1' WHERE mID=%s",
GetSQLValueString($_POST['mID'], "int"));

Is the mID value set correctly in a hidden field? Why not use the Session directly? Also is the form method POST?

Sign in to reply to this post

bjgarner241692

Yes, mID field is properly populated and value is passing, proved this out by calling it in the body of the results page.

Used the session variable to populate it and called the form value in the parameter simply because I was more familiar with the syntax to do it that way.

The call to field 'nothing' is irrelevant. When you use the built in Update Record tool it insists on two fields (One primary and one to be updated), however, it is not referred to in my update statement. Deleted it though and there is no difference.

Yes, form uses POST.

Sign in to reply to this post

Ray BorduinWebAssist

You have:

if ((isset($_POST["button2"])) && ($_POST["button2"] == "form2")) {


but your button value is "Submit", so it should be:

if ((isset($_POST["button2"])) && ($_POST["button2"] == "Submit")) {
Sign in to reply to this post

bjgarner241692

That is it. Thank you very much.

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

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