I always find it difficult to write MySQLi prepared statements, because many functions work differently than in the old way. Right now I am facing a problem regarding
replace this:
$result = $stmt->execute(); while ($row = $result->fetch_array()) {
by this
$stmt->bind_result($category_id); while($stmt->fetch()){ $myArray=$category_id; }