Function vanishing on a single point but not a finite set of points $\subset \mathbb{A}^n$

Suppose $X \subset \mathbb{A}^n$ is an affine variety; Given $p \not\in \{p_1,..,p_k\}$, with $p, p_1, ..., p_k \in X$, how can I find $f \in A(X)$ vanishing on all the $p_i$ but not on $p$?

If $k = 1$, I could just take some hyperplane containing $p_1$ and not $p$. Is it possible to just multiply all such hyperplanes (i.e. the polynomials yielding them as their zero locus)?

EDIT: I stated the problem wrong (the title is correct, though): I want a function $f \in A(X)$ vanishing on $p$ but not on any of the $p_i$. What could I do to obtain such an $f$?

-
Your idea produces correctly a function $f$ which vanishes at all $p_i$ but not at $p$ (at least if the base field is infinite). Then consider the function $f-f(p)$. (Though we have to suppose $p$ is a rational point). Note also that what you want is a direct consequence of the prime avoidance lemma. – user18119 Nov 20 '11 at 0:05
Fantastic, how could I overlook that! Thanks :) The base field K is assumed to be algebraically closed, so this solution should work. – Paul Nov 20 '11 at 9:58

First, remember that for two algebraic sets $V, W \subset \mathbb{A}^{n}$ we have $V = W$ if and only if $I(V) = I(W)$. Since $V = \{ p_{1}, \ldots, p_{k} \}$ and $W = \{ p \}$ are algebraic sets and $V \subsetneq V \cup W$, we have $I(V \cup W) \subsetneq I(V)$. Then there is $f \in I(V) \setminus I(V \cup W)$, that is, $f(p_{i}) = 0$ for $i = 1, \ldots, k$ and $f(p) \neq 0$. Now, just consider $f \in A(X)$.
EDIT: The same argument works well. We have $\{ p \} \subsetneq \{ p, p_{1} \} \subsetneq \cdots \subsetneq \{ p, p_{1}, \ldots, p_{k} \}$, so $I( \{ p, p_{1}, \ldots, p_{k} \} ) \subsetneq \cdots \subsetneq I( \{ p, p_{1} ) \subsetneq I( \{ p \} )$. Then there is $f \in I( \{ p \} ) \setminus \cup_{i=1}^{k} I( \{p, p_{1}, \ldots, p_{i} \} )$, that is, $f(p) = 0$, but $f(p_{i}) \neq 0$, for $i = 1, \ldots, k$.