I am using this code to make threads.
I pass in a userid of 0 so I can put in whatever I want for the username since it is an anonymous user. But if the username matches with someone that has already registered, I get an error message saying the username is not unique!
Is there any way to avoid this error?
I pass in a userid of 0 so I can put in whatever I want for the username since it is an anonymous user. But if the username matches with someone that has already registered, I get an error message saying the username is not unique!
Is there any way to avoid this error?
PHP:
function createThread($userid, $username, $forumId, $subject, $message)
{
$writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
$writer->set('user_id', $userid);
$writer->set('username', $username);
$writer->set('title', $subject);
$postWriter = $writer->getFirstMessageDw();
$postWriter->set('message', $message);
$writer->set('node_id', $forumId);
$writer->preSave();
$writer->save();
return $writer->getMergedData();
}