If you execute both statements in both cases, the second will fail because it already exists. Instead, use array keys in $_mysql and execute only that statement you actually need.