Jump to content

1062 Duplicate Entry - What's Wrong with my code


allex01

Recommended Posts

I'm trying to integrate phpbb with my current site. I want all users who register on my site to also have a duplicate entry in the phpbb user database so that they don't have to signup twice (mysite and phpbb)

I created the following function. When i test i get Fatal error: 1062 Duplicate entry '' for key 2 in /home/user/public_html/register.php on line 255

Line 255 refers to  trigger_error($this->dbObj->ErrorNo().' '.$this->dbObj->ErrorMsg(), E_USER_ERROR); at the very bottom of the code. Here' s the function. What am i doing wrong. I greatly appreciate any help.

 

public function insertFormFieldsInPHPBB3UserTable($user_table_name, $fields_to_insert_arr=array())

{

$field_names_separated_by_comma = 'doj, ';

$parameters_separated_by_comma  = $this->dbObj->SQLDate('Y-m-d H:i:s').', ';

 

$paramFields = array();

$temp_username = $this->fields_arr['user_name'];

 

$this->fields_arr['user_name'] = ucfirst(strtolower(($this->fields_arr['user_name'])));

 

// field name, parameters and fields value are set

foreach($fields_to_insert_arr as $field_name)

if (isset($this->fields_arr[$field_name]))

{

$field_value = $this->fields_arr[$field_name];

$field_names_separated_by_comma .= $field_name.', ';

 

$parameters_separated_by_comma .= $this->dbObj->Param($field_value).', ';

$paramFields[] = $field_value;

$$field_name = $field_value;

}

 

$sql = "INSERT INTO `phpbb_users` ".

" ( `user_id`, `user_type`, `group_id`, `user_permissions`, `user_perm_from`, `user_ip`, `user_regdate`, `username`, `username_clean`, `user_password`, `user_passchg`, `user_pass_convert`, `user_email`, `user_email_hash`, `user_birthday`, `user_lastvisit`, `user_lastmark`, `user_lastpost_time`, `user_lastpage`, `user_last_confirm_key`, `user_last_search`, `user_warnings`, `user_last_warning`, `user_login_attempts`, `user_inactive_reason`, `user_inactive_time`, `user_posts`, `user_lang`, `user_timezone`, `user_dst`, `user_dateformat`, `user_style`, `user_rank`, `user_colour`, `user_new_privmsg`, `user_unread_privmsg`, `user_last_privmsg`, `user_message_rules`, `user_full_folder`, `user_emailtime`, `user_topic_show_days`, `user_topic_sortby_type`, `user_topic_sortby_dir`, `user_post_show_days`, `user_post_sortby_type`, `user_post_sortby_dir`, `user_notify`, `user_notify_pm`, `user_notify_type`, `user_allow_pm`, `user_allow_viewonline`, `user_allow_viewemail`, `user_allow_massemail`, `user_options`, `user_avatar`, `user_avatar_type`, `user_avatar_width`, `user_avatar_height`, `user_sig`, `user_sig_bbcode_uid`, `user_sig_bbcode_bitfield`, `user_from`, `user_icq`, `user_aim`, `user_yim`, `user_msnm`, `user_jabber`, `user_website`, `user_occ`, `user_interests`, `user_actkey`, `user_newpasswd`, `user_form_salt`) ".

 

                            " VALUES(NULL, 0, 2, '', 0, '$signup_ip', ".time().", '".strtolower($user_name)."', '".strtolower($user_name)."', '".

                            md5($password)."', ".time().", 0, '$email', ".

                            crc32(strtolower($email)) . strlen($email).", '', 0, ".

                            time().", 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'en', 0.00, 0, 'D M d, Y g:i a', 1, 0, '', 0, 0, 0, 0, -3, 0, 0, 't', 'd', 0, 't', 'a', 0, 1, 0, 1, 1, 1, 1, 895, '', 0, 0, 0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '2dd6ed4b2fbd6f9b')";

 

 

              $stmt = $this->dbObj->Prepare($sql);

              $rs = $this->dbObj->Execute($stmt);

                  if (!$rs)

                  trigger_error($this->dbObj->ErrorNo().' '.$this->dbObj->ErrorMsg(), E_USER_ERROR);

 

$this->fields_arr['user_name'] = $temp_username;

return $this->dbObj->Insert_ID();

}

Link to comment
Share on other sites

Well i guess there is no way that u can have a duplicate entry of each user in "phpbb_users" u can use this table on your site by making a link with the database on ur own page i guess that would make u to do what u want to . ::)

just like open the connection with "phpbb_users" and then do the authenctication stuff and other i guess ::)

Link to comment
Share on other sites

well as far as mysql is concerned there is some sort of restriction in phpbb_users for the duplicate values which u r entering might by one of these

 

$sql = "INSERT INTO `phpbb_users` ".
                      " ( `user_id`, `user_type`, `group_id`, `user_permissions`, `user_perm_from`, `user_ip`, `user_regdate`, `username`, `username_clean`, `user_password`, `user_passchg`, `user_pass_convert`, `user_email`, `user_email_hash`, `user_birthday`, `user_lastvisit`, `user_lastmark`, `user_lastpost_time`, `user_lastpage`, `user_last_confirm_key`, `user_last_search`, `user_warnings`, `user_last_warning`, `user_login_attempts`, `user_inactive_reason`, `user_inactive_time`, `user_posts`, `user_lang`, `user_timezone`, `user_dst`, `user_dateformat`, `user_style`, `user_rank`, `user_colour`, `user_new_privmsg`, `user_unread_privmsg`, `user_last_privmsg`, `user_message_rules`, `user_full_folder`, `user_emailtime`, `user_topic_show_days`, `user_topic_sortby_type`, `user_topic_sortby_dir`, `user_post_show_days`, `user_post_sortby_type`, `user_post_sortby_dir`, `user_notify`, `user_notify_pm`, `user_notify_type`, `user_allow_pm`, `user_allow_viewonline`, `user_allow_viewemail`, `user_allow_massemail`, `user_options`, `user_avatar`, `user_avatar_type`, `user_avatar_width`, `user_avatar_height`, `user_sig`, `user_sig_bbcode_uid`, `user_sig_bbcode_bitfield`, `user_from`, `user_icq`, `user_aim`, `user_yim`, `user_msnm`, `user_jabber`, `user_website`, `user_occ`, `user_interests`, `user_actkey`, `user_newpasswd`, `user_form_salt`) ".

 

you should check the schema of phpbb_users table which is in the install directory of the phpbb set files that which values are set to be primary key (which is for sure unique)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.