I want to make an insert only if there's no correspondence in the db (mySQL) but he makes me not the statement. Here's the snippet
if ($sql->rowCount() > 0) {
echo 'Non inserisci';
} else {
echo 'Inserisci';
$db->beginTransaction();
echo 'Ciao3';
$sql = $db->prepare("INSERT INTO contatti (nome,cognome) VALUES (?,?)") or die('Ciao2');
echo 'Ciao4';
$sql->execute(array($_POST['nome'],$_POST['cognome']));
echo 'Ciao5';
$db->rollBack();
}
Where The SELECT is
$db->beginTransaction();
$sql = $db->prepare("SELECT * FROM contatti WHERE nome = ? AND cognome = ? WHERE nome = ? AND cognome = ?") or die ('Ciao1');
$sql->execute(array($_POST['nome'],$_POST['cognome']));
$db->rollBack();
Can you explain me where's the fault?