Dodgeman is correct. You need to tie the end-stud to the joists with bolts in 3 places. (2 just isn't enough.) Another options is to consider a 4 x 4 piece of wood. It's the same 'width' as the 2 x 4. If you can picture the Knewl Post of a stair rail system, it's tied to the floor joist, or at least cross-braced from below, and tied to something down there.