I have a function that first checks to see a row exists and if it doesn’t it inserts data. If anything fails it is supposed to return false. When I run the function and check the return with a var_dump, it returns true. I’m to assume that the data is inserted into the database, but it is not. Why would it do this? Is there something wrong with my function?
function add_tier ($mysqli, $project_id, $tier_number, $wanted, $in_return, $limit) {
if ($result = $mysqli->query("SELECT COUNT(tier_id) FROM `tier` WHERE `project_id`
= $project_id AND `tier_number` = $tier_number")){
if ($return < 1) {
if ($stmt = $mysqli->prepare("INSERT INTO `tier` (`project_id`,
`tier_number`, `wanted`, `in_return`, `limit`) VALUES (?, ?, ?, ?, ?)")){
$stmt->bind_param('iissi', $project_id, $tier_number, $wanted, $in_return,
$limit);
$return = $stmt->execute();
$stmt->close();
return $return;
} else {return false;}
} else {return false;}
} else {return false;}
}
(Continuing from comments) You don’t appear to have defined the
$returnin this line anywhere: