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. Are you completing this survey from…?

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

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');

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


# Return
return $included;
End Unverified

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

answered Oct 18, 2018 by Zachary Platinum Sawtooth Software, Inc. (205,575 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.
I put this code in the skip logic for the first page on the survey. I filled all the parameters with the information from the Sawtooth hosting project information as in:
my $databaseName = 'db_xxxxx';
my $databaseUser = 'user_xxxxx';
my $databasePass = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
my $databaseHost = '3.primarydb.sawtoothsoftware.com';

What value should I put in my $table= ' '?
I put my $table='IPaddress() '
I can now enter the survey, but doesn't do anything even if the IP address is the same.