PC Nerd Posted January 21, 2007 Share Posted January 21, 2007 i have the following code, but it says that there is a duplicate entry or something.... here is the error:Duplicate entry '0' for key 1SQL= INSERT INTO General_Stats (User_Name, `Password`, Email, Security_Number, F_Name, L_Name, Age, Account_Created, Rank, Level, Active, Attack, Defense, Sustainability, Resource_1, Resource_2, Resource_3, Friends, Religeon) VALUES ('Bogus1', 'PASSWORD', 'TRUE EMAIL', '4361 - 452 - 858', 'NAME', 'L_NAME', '17 - 25', '21/01/2007 13-25-43', '3', '1', 'NOT_ACTIVE', '1', '1', '1', '200', '0', '0', '0', '0')here is the code:[code]<?phpinclude("inc_files\Database_link.inc");$rank_query = "SELECT User_Name FROM General_Stats order by Rank DESC";#$current_rank = '1';#if ($Rank_Query_Result = mysqli_query($DB_Server, $rank_query)) {# if (mysqli_num_rows($Rank_Query_Result) > 0) {# while ($row = mysqli_fetch_assoc($Rank_Query_Result)) {# $current_rank++;# }# }#}if ($Rank_query_result = mysqli_query($DB_Server, $rank_query)) { $current_rank = mysqli_num_rows($Rank_query_result); $current_rank ++;}$User_Name = $_POST['User_Name'];$Password = $_POST['Password'];$Email = $_POST['Email'];$Security_Number = $_POST['Security_Number'];$F_Name = $_POST['F_Name'];$L_Name = $_POST['L_Name'];$Age = $_POST['Age'];$_POST['Created'] = date("d/m/Y H-i-s");$Created = $_POST['Created'];$_POST['Rank'] = $current_rank;# + 1;$Rank = $_POST['Rank'];#$subject = "New Battle Ages Acccount Confirmation";#$Message = "To ".$F_Name."<br>";#$Message = $Message."User Name :".$User_Name."<br>";#$Message = $Message."Password :".$Password."<br>";#$Message = $Message."Security Number :".$Security_Number."<br><br>";#$Message = $Message."Please type your Security Number into the field below ( with no spaces or dash's), to activate your account";#$Message = $Message."Thankyou for signing up to Battle-Ages. Please email us a the above address for help and support.<br><br>Yours, Battle-Ages Administraion Team";#$header = "From: admin@battle-ages.itsmyland.com";#$Send_Mail = mail($to, $subject, $Message, $header);$New_Player_SQL = "INSERT INTO General_Stats (User_Name, `Password`, Email, Security_Number, F_Name, L_Name, Age, Account_Created, Rank, Level, Active, Attack, Defense, Sustainability, Resource_1, Resource_2, Resource_3, Friends, Religeon) VALUES ('$User_Name', '$Password', '$Email', '$Security_Number', '$F_Name', '$L_Name', '$Age', '$Created', '$Rank', '1', 'NOT_ACTIVE', '1', '1', '1', '200', '0', '0', '0', '0')";$New_Player_Query = mysqli_query($DB_Server, $New_Player_SQL)or die("<h3>Error</h3>\n<br><br>\n<p>An error has occured while submitting your details to the Database. As a result your account has not been created, although you may still receive your confirmation email. If you do receive your Email, please ignore it, and resubmit your account request in 24 hours.</p><br><br>".mysqli_error($DB_Server)."SQL= ".$New_Player_SQL);[/code]there is more code below that but im 99% sure its irrelevantid appreciate any help with explainging the error and finding the code cauaseing it and help to fix the error, THANKS Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 21, 2007 Share Posted January 21, 2007 Mind telling us what DB libary you are using? Edit: Sorry, I'm not sure how this works. Sorry again. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 i dont understand ??? Quote Link to comment Share on other sites More sharing options...
scotmcc Posted January 21, 2007 Share Posted January 21, 2007 I am no expert, but it looks like you are trying to insert a row into the database, and you are specifying a value to insert into a row on a table, which has a unique index.For example, if you have an 'id' field or sequence and it is a UNIQUE value and you insert a row with an ID of '0' then later try to do the same thing, you will get an error. I'd look into your database and check to see if you have a record with a zero in the position you are receiving an error for. Then, check to see if you have a unique index on that field. If you do, make sure you are inserting a unique entry into that field.Scot Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 wqell i know that the field extra is auto_increment, thats in the mysqli databas itsself ( im using phpmyadmin)also, i thought the code section if ($Rank_query_result = mysqli_query($DB_Server, $rank_query)) { $current_rank = mysqli_num_rows($Rank_query_result); $current_rank ++;}would have created the unique ID, or sles the code above it that ive commented out. Quote Link to comment Share on other sites More sharing options...
Destruction Posted January 21, 2007 Share Posted January 21, 2007 I've come across this recently. Double check your primary key has it's auto_increment defined. If not, this will need adjusting otherwise every entry attempted on INSERT without specifying a unique id will fail. This has happened when I've moved a database from one server to another with a different version so I suspect when I came across it it was a compatibility issue perhaps.Dest Quote Link to comment Share on other sites More sharing options...
scotmcc Posted January 21, 2007 Share Posted January 21, 2007 I did some searching on Google and found an interesting discussion about this error, looks like it has to do with the users table, read this, if you don't understand this discussion, let me know.http://drupal.org/node/21120Scot Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted January 21, 2007 Author Share Posted January 21, 2007 thanks, that solved it.i had resecently re made my database from scratch with a new design, and had forgot to make the autoincrement option activethanks 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.