Your reasoning is wrong in that it doesn't take into account the space your variables and equations belong to. This is not in any ways your fault: I have NEVER seen a thorough explanation of Lagrangian and Hamiltonian dynamics in an introduction to quantum mechanics. Here is how it works.
Lagrangian and Hamiltonian dynamics (at least in the context of particle dynamics, i.e. not of field dynamics) are dual theories, in the sense that they are equivalent theories that are defined on dual spaces (in the sense of vector spaces). The Lagrangian is a function given on a set known as a tangent bundle. The Hamiltonian is a function given on a set known as a cotangent bundle, which, in a sense that will be clear soon, is the dual space to the tangent bundle.
Let's say you have a configuration space $X$. This can be, for example, the 3-dimensional space of the positions of a particle in physical space, or the 3N-dimensional space of the positions of N particles in physical space. The tangent bundle associated to $X$ is denoted with $TX$ and consists of the space of vectors attached to each and every point of $X$. There is a rigorous definition of $TX$, but for the purpose of answering to your question, let us define $TX$ as
$$
TX=\coprod_{x\in X}T_{x}X
$$
where $T_{x}X$ is the vector space which contains the vectors attached to $x\in X$, and $\coprod$ is the disjoint union of its argument for $x\in X$, i.e.
$$
TX\ni(x^{i},\dot{x}^{i})
$$
where we denote with $\dot{x}^{i}$ the $i$-th component of some vector. The Lagrangian $\mathscr{L}$ is a real function on $TX$, while the action is a functional on the space of curves on $X$:
$$
S[x(t)]=\int_{a}^{b}\mathscr{L}(x^{i}(t),\dot{x}^{i}(t))\ dt
$$
where $x:\Bbb{R}\to X$ is a curve and the $\dot{x}^{i}$'s are given by $dx^{i}/dt$. The action is minimized when the Euler-Lagrange equations
$$
\frac{\partial\mathscr{L}}{\partial x^{i}}(x(t),\dot{x}(t))-\frac{d}{dt}\frac{\partial\mathscr{L}}{\partial \dot{x}^{i}}(x(t),\dot{x}(t))=0
$$
are satisfied. These equations, though, are equations on $TX$, with an additional $\Bbb{R}$-dependence (in a rigorous formulation, $TX$ should really be replaced with $T(\Bbb{R}\times X)$). In $TX$, $x^{i}$ and $\dot{x}^{i}$ are independent variables, so indeed here there is no derivative $\partial \dot{x}^{i}/\partial x^{j}$.
The cotangent bundle associated to $X$ is denoted with $T^{*}X$ and defined by
$$
T^{*}X=\coprod_{x\in X}T^{*}_{x}X
$$
where $T^{*}_{x}X$ is the dual space of $T_{x}X$. We have
$$
T^{*}X\ni(x^{i},p_{i})
$$
where the $p_{i}$'s are the components of the element in $T_{x}^{*}X$. The Hamiltonian $\mathscr{H}$ is a function on $T^{*}X$. To go from Lagrangian to Hamiltonian dynamics, we define the so called Legendre transform associated to $\mathscr{L}$. This is the function
$$
\Bbb{F}\mathscr{L}:TX\to T^{*}X
$$
defined by
$$
\Bbb{F}\mathscr{L}(q^{i},\dot{q}^{i})=\left(q^{i},\frac{\partial\mathscr{L}}{\partial \dot{q}^{i}}(q^{i},\dot{q}^{i})\right)
$$
Let's suppose that $\Bbb{F}\mathscr{L}$ is invertible. Then we have a function $\Bbb{F}\mathscr{L}^{-1}:T^{*}X\to TX$ and we can define the Hamiltonian $\mathscr{H}$ as
$$
\mathscr{H}:T^{*}X\to \Bbb{R},\qquad\quad \mathscr{H}(q^{i},p_{i})=\min_{\dot{q}}\left\{p_{i} \dot{q}^{i}-\mathscr{L}\left(q^{i},\dot{q}^{i}\right)\right\}
$$
It's easily seen that
$$
0=\frac{\partial}{\partial \dot{q}^{i}}\ \left\{p_{i} \dot{q}^{i}-\mathscr{L}(q^{i},\dot{q}^{i})\right\}=p_{i}-\frac{\partial \mathscr{L}}{\partial \dot{q}^{i}}\left(q^{i},\dot{q}^{i}\right)
$$
i.e. iff $(q^{i},p_{i})=\Bbb{F}\mathscr{L}(q^{i},\dot{q}^{i})$ (so that in turn $(q^{i},\dot{q}^{i})=\Bbb{F}\mathscr{L}^{-1}(q^{i},p_{i})$). Again, $q^{i}$ and $p_{i}$ are independent variables in $T^{*}X$. Moreover, as the $\dot{q}^{i}$'s in $\mathscr{H}$ are held fixed by the minimum condition,
$$
d\mathscr{H}=\dot{q}^{i}dp_{i}-\frac{\partial\mathscr{L}}{\partial q^{i}}dq^{i}
$$
and of course
$$
d\mathscr{H}=\frac{\partial\mathscr{H}}{\partial q^{i}}dq^{i}+\frac{\partial\mathscr{H}}{\partial p^{i}}dp^{i}
$$
both with the correct relation between $(q^{i},\dot{q}^{i})$ and $(q^{i},p_{i})$, so that
$$
\dot{q}^{i}(t)=\frac{\partial\mathscr{H}}{\partial p^{i}}(q^{i}(t),p_{i}(t)),\qquad\quad \dot{p}_{i}(t)=\frac{d}{dt}\frac{\partial\mathscr{L}}{\partial \dot{q}^{i}}\left(\Bbb{F}\mathscr{L}^{-1}(q^{i}(t),p_{i}(t))\right)=\frac{\partial\mathscr{L}}{\partial q^{i}}\left(\Bbb{F}\mathscr{L}^{-1}(q^{i}(t),p_{i}(t))\right)=-\frac{\partial\mathscr{H}}{\partial q^{i}}\left(q^{i}(t),p_{i}(t)\right)
$$
These are equations on $T^{*}X$ and, as such, there is no derivative $\partial p_{i}/\partial x^{j}$. Again, in order to be able to derivate with respect to $t$, $T^{*}X$ should really be extended to $T^{*}(\Bbb{R}\times X)$.
The problem with the switch between Lagrangian and Hamiltonian dynamics is that it must be formulated in VERY rigorous terms. The formulation I gave above is not by any means the only one, and it doesn't take care of many aspects which in more complicated theories are not by any means trivial. In each of the spaces $TX$ and $T^{*}X$, the $q^{i}$'s are independent of the $\dot{q}^{i}$'s and the $p_{i}$'s, but the $\dot{q}^{i}$'s in the action are not independent of the $q^{i}$'s, and the $(q^{i},p^{i})$'s are made to depend (ONLY in the switch between the two formulations, not in the dynamical equations) upon the $(q^{i},\dot{q}^{i})$'s by the Legendre transform.