$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO cinema (name, genre, year, oscar, watched) VALUES(?,?,?,?,?)";
$q = $pdo->prepare($sql);
$q->execute(array($name, $genre, $year, $oscar, $seen));
Database::disconnect();
1 Answer
Just do another query before you do the INSERT:
SELECT COUNT(*) as c FROM cinema WHERE name = ? and year = ?
Do the usual prepare/bind/fetch stuff and if ($row['c'] > 0) then you output your error message - otherwise you continue to your INSERT.
1 Comment
joe_black
can you plz share the prepare/bind/fetch stuff
UNQIUEconstraints), but the question is, what should happen after the table is queried before theINSERT. Either give an error (so the first query is useless anyway) or do anUPDATE(which has been asked&answered a ton of times as well)