so my newest problem! i have a save button and that save button already has the insert into query and working fine now what i wanna do is when the user clicks on the save button what it does first is, it checks if a record of that user already exists and if there already is a record in regards to that user then instead of inserting it will update the table. and if there isnt a record then it will just insert.

what i have so far:

<?php  

include('connect.php');

if(isset($_POST['action']) && $_POST['action'] === 'saveIteration'){

    $distanta = $_POST['distanta'];
    $durata_calatorie = $_POST['durata_calatorie'];
    $start = $_POST['start'];
    $end = $_POST['end'];

    $add_new_input = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    $add_new_input_query = "INSERT INTO ".$DB_TABLE." (distanta , durata , start ,end ) VALUES(? , ? , ? , ?)";
    if ($add_new_input_stmt = $add_new_input ->prepare($add_new_input_query)) {
        $add_new_input_stmt ->bind_param("ssss",$distanta , $durata_calatorie , $start , $end);
        $add_new_input_stmt ->execute();
        $add_new_input_stmt ->close();
    }
    $add_new_input->close();

}

?> 

Show your table creat SQL code. I do not know what primary or unique keys is set to the table. Example if unique key is person_id

INSERT INTO ".$DB_TABLE." (`person_id`, `distanta` , `durata` , `start` , `end` )
VALUES(? , ? , ? , ? , ?)
ON DUPLICATE KEY UPDATE
SET `distanta` = VALUES(`distanta`)
,`durata` = VALUES(`durata`)
,`start` = VALUES(`start`)
,`end` = VALUES(`end`);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.