allex01 Posted February 28, 2008 Share Posted February 28, 2008 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(); } Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 28, 2008 Share Posted February 28, 2008 This isn't a PHP error at all. It's a MySQL error. Your table is setup to have a unique index and it is returning an error when two different rows have the same value for this "unique" ID. Quote Link to comment Share on other sites More sharing options...
allex01 Posted February 28, 2008 Author Share Posted February 28, 2008 I'm signing up using different info. The way the have the insert, wouldn't that auto increment user_id, why would i have duplicate rows. Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 28, 2008 Share Posted February 28, 2008 Instead of doing INSERT INTO `phpbb_users` (`user_id`, ...OTHER COLUMNS...) VALUES (NULL, ...OTHER COLUMNS...) Take out user_id from the fields, and remove NULL from the VALUES. this should solve your problem. Quote Link to comment Share on other sites More sharing options...
allex01 Posted February 28, 2008 Author Share Posted February 28, 2008 Yes, i tried. No success. Any other suggestions. I've been working on this all day, and can't figure out duplicate entry problem. Quote Link to comment Share on other sites More sharing options...
Baabu Posted February 28, 2008 Share Posted February 28, 2008 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 Quote Link to comment Share on other sites More sharing options...
allex01 Posted February 28, 2008 Author Share Posted February 28, 2008 My questions was what's is causing the duplicate entry issue. Quote Link to comment Share on other sites More sharing options...
Baabu Posted February 28, 2008 Share Posted February 28, 2008 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.