Php click counter

hi have this script that update its table accounter
but the script seem to update when i refresh the page i havent even figure out the button click to update the table +1 instead when i refresh the browser i get updated, plz what am i doing wrong here and how do i add the button that will b click to download d file n update the table +1.

thanks\

if (isset($_POST['action']) && $_POST['action'] == 'update')
        {
        
    //all_clicked    

    $query = "INSERT INTO `" . $DBPrefix . "auccounter` (`auction_id`, `download_counter`) VALUES (:download_counter, 1)";
    $params = array();
    $params[] = array(':download_counter', $id, 'int');
    $db->query($query, $params);
        $auction_data['download_counter'] = 1;

    }
    
else{
        
        
    $query = "UPDATE " . $DBPrefix . "auccounter set download_counter = download_counter + 1 WHERE auction_id = :auction_id";
        $params = array();
        $params[] = array(':auction_id', $id, 'int');
        $db->query($query, $params);

}
while ($row = $db->fetch())
{
    $template->assign_block_vars('click', array(
            'DOWNLOAD' => $auction_data['download_counter']
            ));
}


When you refresh the page, your $_POST variables are not set, hence it runs the code in your else{} clause which, in this case, runs the update code. I don’t know what value it uses for $id, but that’s why it is doing it.

Oh okay
But am i fixing i mean how do i make d adjustment plus i still cant get d button to work also, sorry 4 d question n thanks 4 ur replies

Not really sure what you’re asking there, with all the shorthand and stuff.

I think to do a download count, you’d have the button call your PHP code, the PHP code updates the count in the database, then loads the file and sends it to the browser with an appropriate header to tell the browser the file type and that it needs to be downloaded rather than opened.

Yeah thsta wat i want to accomplish been building it all by my self this is almlst 75% done a bit of assistance wud b grate ful, too many short nite rest for me.

Will b glad if u assist thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.