将JS数组传递给PHP,然后更新MySQL

I have a problem. The story so far:

PHP1 reads an array from the database, that contains only integers - it has the following form:
[0, 70, 44, ...]

Because the number of entities it contains varies, I want to be able to read and store the whole array into one cell of the database - the solution must not disregard this, then.

PHP1 contains some JS, that allows a user to do something on the website, which alters one of the entities in the array, which makes it, e.g.;
[0, 75, 44, ...]

So far, so good.

Now I want this new array to replace the one in the database, this is the central goal that I fail to achieve.


What I'm currently working with - which isn't working:

PHP1 executes some AJAX magic, and sends this array to PHP2, which works fine:

var arrayX = [0, 75, 44, ...];
var arrayY = JSON.stringify(arrayX);

$.ajax({
    url: 'PHP2.php',
    type: 'post',
    data: {arrayY: arrayY }
});

PHP2 then connects to the DB, and attempts to update that one cell with the new array, by means of the following, which doesn't work (!):

$arrayZ = json_decode($_POST['arrayY'], true);

mysql_query("UPDATE userbase SET db_column = $arrayZ WHERE id=0", $con);

mysql_close($con);

I've tried serializing $arrayZ in PHP2, as well as a whole set of other solutions I found on Stackoverflow, but none of them worked (or I didn't apply them correctly of course) and now I've found myself deadstruck...


I'm hoping your talents will get me further than my own have!

I assume db_column holds a string value, and as such you probably just need quotes around $arrayZ in your SQL string.

mysql_query("UPDATE userbase SET db_column = '$arrayZ' WHERE id=0", $con);

But as Fake51 pointed out, your database schema is flawed.

Also, you're susceptible to a SQL Injection attack.