Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

how to validate and terminate people answering multiple time from same IP address

How can we validate and terminate people answering multiple time from same IP address  we have following instruction "TERMINATE IF QS0=1 AND IP ADDRESS HAS STATUS=COMPLETE "


S1 SURVEY LOCATION
S1. Are you completing this survey from…?
SINGLE RESPONSE, RANDOMISE

1.    Home
2.    Work
3.    A public place e.g. library, airport, etc.

TERMINATE IF QS0=1 AND IP ADDRESS HAS STATUS=COMPLETE
asked Oct 17, 2018 by Nischay

1 Answer

0 votes
Skip logic:

Begin Unverified Perl
# Parameters
my $table = '';

my $databaseName = '';
my $databaseUser = '';
my $databasePass = '';
my $databaseHost = '';

# IP Address
my $ip = GETVALUE('sys_IPAddress');

# Read database
my $dbh = DBI->connect('dbi:mysql:' . $databaseName . ':' . $databaseHost, $databaseUser, $databasePass);
my $sth = $dbh->prepare('SELECT `sys_IPAddress` FROM `' . $table . '` WHERE `sys_IPAddress` IS NOT NULL AND `sys_IPAddress` <> "" AND `sys_RespStatus` IS NOT NULL AND `sys_IPAddress` = 5');
$sth->execute();

my $included = 0;
while (my $row = $sth->fetchrow_arrayref()) {
    my $resp = $row->[0];
    if ($resp eq $ip) {
        $included = 1;
        last;
    }
}

$sth->finish;
$dbh->disconnect;

# Return
return $included;
End Unverified


The "# Parameters" section must be filled out according to the instructions here:

https://sawtoothsoftware.com/community-question-library/1752-read-database
answered Oct 18, 2018 by Zachary Platinum Sawtooth Software, Inc. (111,725 points)
Thanks Zackary, let me put this script and test. Thanks heaps for your help.
I am getting error but difficult for me to understand, can you guide further.

I am emailing you detail of error since its screen shoot of database detail so can't share here.
You're using self hosting, correct?  If so, you may need to consult with whoever on your team operates the server for help in fixing this.  This person should be able to double check that the table name and database credentials you are using are correct, as well as check that DBI is installed on the server.
...