Page 1 of 1

Duplicate entry '25510' for key 1

Posted: Mon Apr 07, 2008 2:23 am
by psychotomus
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


what does that error mean? How do I fix it?
I'm using the phpBB2.0 template system

Code: Select all

 
<? 
include("includes.php");
$template = &New Template;
$template->set_filenames(array('header' => 'templates/enterstation/header.tpl'));
$template->set_filenames(array('body' => 'templates/enterstation/add_cheat.tpl'));
$template->set_filenames(array('ad' => 'templates/enterstation/ad.tpl'));
$template->set_filenames(array('footer' => 'templates/enterstation/footer.tpl'));
include("actions.php");
 
$template->assign_vars(array("TITLE" => $siteTitle,
                            "SITE_URL" => $siteURL,
                            "PAGE" => "Add Cheat Code"));
                            
@set_time_limit(100000000);
$game_id = mysql_real_escape_string($_GET['id']);
 
 
$result = mysql_query("SELECT * FROM game_data WHERE id='$game_id'") or die(mysql_error());
$game_data = mysql_fetch_object($result);
 
//if not submitting any data
if ( (!isset($HTTP_POST_VARS['Submit'])) && (!isset($HTTP_POST_VARS['Submit2'])) )
{
    $template->assign_vars(array('GAME_NAME' => $game_data->name,
                          'GAME_PLATFORM' => $game_data->platform));
    $template->assign_block_vars('switch_part_1',array() );
}
else
{
    //if part 1 of submitting cheat code
    if( isset($HTTP_POST_VARS['Submit']) )
    {
        $template->assign_block_vars('switch_part_2',array() );
        $cheat_count = $HTTP_POST_VARS['cheat_count'];
        $template->assign_var('TOTAL_CHEATS' , $cheat_count);
        for($i=0; $i<$cheat_count; $i++)
        {
            $template->assign_block_vars('add_cheats',array(    'NUM' => $i,
                                                                'NUM1' => $i+1));
        }
    }
    //if part 2 of submitting cheat code
    if( isset($HTTP_POST_VARS['Submit2']) )
    {
        
        //$files = array_values($HTTP_POST_VARS['file']);
        $file_count = $HTTP_POST_VARS['hiddenField'];
        
        $username = $_SESSION['username'];
 
        //loop threw all screen shots submitted
        for ($x =0; $x < $file_count; $x++)
        {
            //if file field not blank
            if ($_POST['cheat_title'][$x] <> "")
            {
                $title = mysql_real_escape_string($_POST['cheat_title'][$x]);
                $cheat = mysql_real_escape_string($_POST["cheat"][$x]);
                $time = time();
                //insert screen shot info
                $sql = "INSERT INTO game_cheats (username, game_id, cheat_title, cheat, the_date, approved) VALUES ('$username', '$game_id', '$title', '$cheat', '$time', 'n')";
                mysql_query($sql) or die(mysql_error());
            }
        }
        $template->assign_var('MESSAGE' , "<strong>Cheat(s) Submitted. They will be added to the site after being approved</strong>");
    }
}
//display page
$template->pparse('header');
$template->pparse('body');
$template->pparse('ad');
$template->pparse('footer');
?>
 

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Duplicate entry '25510' for key 1

Posted: Mon Apr 07, 2008 10:14 am
by andym01480
Quick guess from looking at your code.

You have got two tables I can see
game_data which has as it's key game_id
game_cheats which also has as it's key game_id? But if you have two cheats for the same game, then you will be duplicating the key which throws the error.

Keep the game_id in game_cheats so you know which game the cheat is for but have a new key say cheat_id which auto-increments and is thus always unique.

Hope that helps!

Re: Duplicate entry '25510' for key 1

Posted: Mon Apr 07, 2008 4:12 pm
by psychotomus
the Keys are id. not game_id. game_id is just my variable to point to id.
Also game_cheats has unique key id which is auto-increment. the problem must lye when selecting from game_data as it shouldn't execute the game_cheats insert cause as soon as it loads the page, it gets that error.