Jump to content

SQL duplicate error


PC Nerd

Recommended Posts

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]<?php
include("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 irrelevant

id appreciate any help with explainging the error and finding the code cauaseing it and help to fix the error, THANKS
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
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.