aebstract Posted March 5, 2010 Share Posted March 5, 2010 Here is my entire page: <?php include_once "connect.php"; $textData = file('array.txt'); $dataArray = array(); $tempArray = array(); $array_start = false; foreach ($textData as $line) { if ($array_start && preg_match("/\[([^\]]*)\] => (.*)/", $line, $keyValue)!= 0) { $tempArray[$keyValue[1]] = $keyValue[2]; } if(substr($line, 0, 1)=='(') { $array_start = true; } if(substr($line, 0, 1)==')') { $array_start = false; $dataArray[] = $tempArray; $tempArray = array(); } } for ($i = 0; $i <= 3664; $i++) { $emailhash = $dataArray[$i][2]; $emailhash = crc32(strtolower($emailhash)) . strlen($emailhash); $query = mysql_query(" INSERT INTO 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_dst, 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_new, user_reminded, user_reminded_time) VALUES ('$dataArray[$i][0]', '0', '2', '', '0', '', '$dataArray[$i][3]', '$dataArray[$i][1]', '$dataArray[$i][1]', '', '', '0', '$dataArray[$i][2]', '$emailhash', '', '0', '', '0', '', '', '0', '', '0', '0', '0', '0', '$dataArray[$i][4]', 'en', 'dst', '1', '0', '', '0', '0', '0', '0', '-3', '0', '0', 't', 'd', '0', 't', 'a', '0', '1', '0', '1', '1', '1', '1', '230271', '', '0', '0', '0', '', '0', '0', '0') ") or DIE(mysql_error()); $query2 = mysql_query("INSERT INTO user_group (group_id, user_id, group_leader, user_pending) VALUES ('2', '$dataArray[$i][0]', '0', '0'')") or DIE(mysql_error()); $query3 = mysql_query("INSERT INTO user_group (group_id, user_id, group_leader, user_pending) VALUES ('7', '$dataArray[$i][0]', '0', '0'')") or DIE(mysql_error()); } ?> What does the error mean? If I know what it's trying to say more clearly, maybe I can get it fixed? Is it just saying that $dataArray[$i][2] contains a duplicate somewhere? Is that not okay? Quote Link to comment https://forums.phpfreaks.com/topic/194291-duplicate-entry-array1-for-key-2/ Share on other sites More sharing options...
freakstyle Posted March 5, 2010 Share Posted March 5, 2010 can you post the full error message, with line number or is this error generated from mysql? if it's mysql, it looks like your saving a value of 'Array[1]' in a database field that does not allow for duplicate values. Look at the data in your database and you should see this pretty clearly, if you see that string in your table you've found where it's failing. You should update your syntax: $string = "SELECT * FROM foo WHERE id IN ('" . $dataArray[$i][0] . "')"; Also, in your IN condition you have repeated values for some reason, i see 0 in there at least a dozen times, you only need it once, think of it like keys in an array. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/194291-duplicate-entry-array1-for-key-2/#findComment-1022123 Share on other sites More sharing options...
Psycho Posted March 5, 2010 Share Posted March 5, 2010 LOL, That's my code from your other post today. What is the specific line that is producing the error? In any event that is some VERY inefficient code. First of all you are creating a loop with an artificial limit instead of using the actual count of the array and you only need to do one query to insert all the values. Quote Link to comment https://forums.phpfreaks.com/topic/194291-duplicate-entry-array1-for-key-2/#findComment-1022126 Share on other sites More sharing options...
aebstract Posted March 5, 2010 Author Share Posted March 5, 2010 LOL, That's my code from your other post today. What is the specific line that is producing the error? In any event that is some VERY inefficient code. First of all you are creating a loop with an artificial limit instead of using the actual count of the array and you only need to do one query to insert all the values. The error is exactly what I posted. That is all of the information that I get, then a white blank screen. I can post the entire array.txt file as it sits when I get back to work (about 15-20 minutes). mjdamato, I tried to get the serialize to work but I don't have the time to wait, you mentioned this code and it worked. If it is so inefficient, why did you suggest it? freakstyle: this isn't a select query, inserting information Quote Link to comment https://forums.phpfreaks.com/topic/194291-duplicate-entry-array1-for-key-2/#findComment-1022141 Share on other sites More sharing options...
freakstyle Posted March 5, 2010 Share Posted March 5, 2010 doesn't matter if you have a select query or an insert, the syntax is what i was highlighting. Notice how a variable is not inside the double quoted string. However that does moot my comment on duplicate strings. as for the error, if it's a php error, it will give you more information. Did you check your table to see if you have that string in there in one of the rows? Does the error happen before or after you send your query? that should be an easy one to test, just place an exit(); before your mysql calls. Quote Link to comment https://forums.phpfreaks.com/topic/194291-duplicate-entry-array1-for-key-2/#findComment-1022147 Share on other sites More sharing options...
aebstract Posted March 5, 2010 Author Share Posted March 5, 2010 I noticed that a line did get entered in the database, but instead of the values showing up, it showed as Array[1], Array[2], etc. Should be easier to fix now that I noticed that. Quote Link to comment https://forums.phpfreaks.com/topic/194291-duplicate-entry-array1-for-key-2/#findComment-1022150 Share on other sites More sharing options...
Psycho Posted March 6, 2010 Share Posted March 6, 2010 LOL, That's my code from your other post today. What is the specific line that is producing the error? In any event that is some VERY inefficient code. First of all you are creating a loop with an artificial limit instead of using the actual count of the array and you only need to do one query to insert all the values. The error is exactly what I posted. That is all of the information that I get, then a white blank screen. I can post the entire array.txt file as it sits when I get back to work (about 15-20 minutes). mjdamato, I tried to get the serialize to work but I don't have the time to wait, you mentioned this code and it worked. If it is so inefficient, why did you suggest it? As freakstyle stated you should be getting more information with the error - such as a LINE NUMBER which would tell us where the error was occuring. I said YOUR code was inefficient, not mine. If you had provided more information previously I would have been willing to help. There is no reason to read through the entire text file to create an array and THEN go through each record in the array. You can do all the work in one loop - not two. Secondly doing multiple queries in loops puts a HUGE overhead on the server. You could easily combine the values for the multiple records and insert them with one query. Lastly, your loop to insert the records as an artificial limit of 3664. If the data has less values then that you will get an error and if there are more values you will not process them all. Since you are using an array, you should be using foreach(). Even if you expect the array to always contain 3664 records you shoudl still use foreach() and just do a check of the count() on the array for validation. Quote Link to comment https://forums.phpfreaks.com/topic/194291-duplicate-entry-array1-for-key-2/#findComment-1022174 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.