Captain Tycoon
12-24-2013, 01:43 PM
Hi,
I am trying to use DataManager to vote on a specific poll using the following code.
I am aware that the datamanager pollvote will use 'REPLACE INTO', so even if they already voted, it will still update it with the vote specified.
require_once('./global.php');
require_once('./includes/functions_databuild.php');
require_once('./includes/class_dm_pollvote.php');
require_once('./includes/class_dm_poll.php');
global $vbulletin;
$pollvote =& datamanager_init('PollVote', $vbulletin, ERRTYPE_STANDARD);
$pollvote->set('pollid', 125);
$pollvote->set('votedate', TIMENOW);
$pollvote->set('voteoption', 1);
$pollvote->set('userid', 1);
$pollvote->set('votetype', 0);
$pollvote->pre_save;
if(!count($pollvote->errors) < 1)
{
echo "An error occured when voting:". $pollvote->errors[0] . $pollvote->errors[1] . $pollvote->errors[2] ;
}
else
{
$pollvoteid = $pollvote->save;
}
Unfortunately, it does not work - doesn't insert the record into table 'pollvote', and it does not update the record in table 'poll' either. No errors from the if statement either (it runs the else statement).
Edit: Fixed by adding $pollvote->save(); <-- brackets
I am trying to use DataManager to vote on a specific poll using the following code.
I am aware that the datamanager pollvote will use 'REPLACE INTO', so even if they already voted, it will still update it with the vote specified.
require_once('./global.php');
require_once('./includes/functions_databuild.php');
require_once('./includes/class_dm_pollvote.php');
require_once('./includes/class_dm_poll.php');
global $vbulletin;
$pollvote =& datamanager_init('PollVote', $vbulletin, ERRTYPE_STANDARD);
$pollvote->set('pollid', 125);
$pollvote->set('votedate', TIMENOW);
$pollvote->set('voteoption', 1);
$pollvote->set('userid', 1);
$pollvote->set('votetype', 0);
$pollvote->pre_save;
if(!count($pollvote->errors) < 1)
{
echo "An error occured when voting:". $pollvote->errors[0] . $pollvote->errors[1] . $pollvote->errors[2] ;
}
else
{
$pollvoteid = $pollvote->save;
}
Unfortunately, it does not work - doesn't insert the record into table 'pollvote', and it does not update the record in table 'poll' either. No errors from the if statement either (it runs the else statement).
Edit: Fixed by adding $pollvote->save(); <-- brackets