Update column avioding dropping row

hello i have a table called “buttonclicked” it update and insert a value of 1 when a submitbutton is click, the thing is, it insert into the table which is good, but when updating same auction_id it drop a row instead of just updating a column

code for insert and update

//insert button click
        $query = "INSERT INTO " . $DBPrefix . "buttonclicked (auction_id, all_clicked) VALUES(:auction_id, :all_clicked);";
        $params = array();
        $params[] = array(':auction_id', $id, 'int');
        $params[] = array(':all_clicked', $_POST['all_clicked'], 'str');
        $db->query($query, $params);


//update button click
    $query = "UPDATE " . $DBPrefix . "buttonclicked SET all_clicked = :all_clicked
    WHERE auction_id = :auction";
    $params = array();
    $params[] = array(':all_clicked', $_POST['all_clicked'], 'str');
    $params[] = array(':auction', $id, 'int');
    $db->query($query, $params);


how do i solve this, thanks

I can’t see anything in that code that would cause a row to get deleted. Something else must be doing it, surely?

oh no none is deleted it just create another row, i want it not to do that if an id already exist instead it should only update a column in that id

Oh sorry, I took that to mean that it was dropping (deleting) a row (because when you want to delete a table, for example, you use the syntax DROP TABLE), and you showed the table had three rows, then it had two rows, and I presumed that you showed them in order.

Same applies in reverse though, unless you’re calling the INSERT query by mistake, I can’t see how the UPDATE query would insert an additional row.

lol na nothing to do with dropping.
the insert is to first fill up the table and the update is to update a column linked to it button, the updating works but when it update it create another row that part is what i dont get

i even tried this way

//insert button click
        $query = "INSERT INTO " . $DBPrefix . "buttonclicked (auction_id, all_clicked) VALUES(:auction_id, :all_clicked)
        ON DUPLICATE KEY UPDATE all_clicked = all_clicked;";
        $params = array();
        $params[] = array(':auction_id', $id, 'int');
        $params[] = array(':all_clicked', $_POST['all_clicked'], 'str');
        $db->query($query, $params);    
            

same problem, mysql creates a new row after updating existing

found the problem, it was a database id auto increment issue:slight_smile:

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