the $sql works in phpMyAdmin
Fatal error: Call to a member function fetch_assoc() on a non-object in E:\wamp\www\
$sql = "SELECT * FROM `account_plans` WHERE `PlanID` = $p"; while ($row = $sql->fetch_assoc()){ $cost = $row['Cost']; }
You forgot to actually execute the query.
Also, it makes no sense to use a while() loop there since you'd be constantly overwriting the value of $cost before you ever used any of the intermediate values. (Likewise, if you only expect at most one result, it still doesn't make sense to use a loop.)