php - When checkbox is checked it triggers more events

one text

Solution:

Just alter the order which you check the values and use an elseif

You can also remove a fair bit of repeated code.

$pdo = new PDO("mysql:host=localhost;dbname=liamed", "root", "");

$q = "insert into users
              (nume,prenume,inventar)
        values(:nume,:prenume,:obiecte)";
$r = $pdo->prepare($q);

$obiecte = false;

if (isset($_POST['telefonCheck']) && isset($_POST['laptopCheck'])) {
    $obiecte = 'laptop si telefon';
} elseif (isset($_POST['laptopCheck'])) {
    $obiecte = 'laptop';
} elseif (isset($_POST['telefonCheck'])) {
    $obiecte = 'telefon';
}

if ( $obiecte ) {  // only run if one of the above if's changed this from false
    $r->execute(array(":nume" => $_POST['nume'], 
                      ":prenume" => $_POST['prenume'], 
                      ":obiecte"=>$obiecte)
                );
}

Source