I would like to test whether an entry of a particular UID and MID exists in the table user_saved, so here’s what I did
$result = $db->prepare("SELECT * FROM user_saved WHERE UID = ? AND MID = ?");
$result->execute(array($_SESSION['uid'], $itemId['MID2']));
$test = $result->fetch(PDO::FETCH_ASSOC);
if (isset($test)){
exist
} else {
doesn't exist
}
The issue is that I tried with a UID and MID that doesn’t exist, but it always goes into the isset if statement, why is this? What’s a better way to do this?
isset checking whether variable exists or not use strlen function or array count function