well first of, all, this:
$how_many_cats = "SELECT count(*) FROM categories";
$result_how_many = mysql_query($how_many_cats);
if($result_how_many == 0)
{
is wrong it should be like this:
$how_many_cats = "SELECT count(id) as count FROM categories";
$result_how_many = mysql_query($how_many_cats);
$how_many = mysql_fetch_array($result_how_many);
if($how_many['count'] == 0)
{
etc....
the only thing i can think about your switch is that it's lost in an unclosed while or something....... your indenting is pretty poor so i cant really tell, sry....