javascript - Passing JS-array to PHP, then updating MySQL -
i have problem. story far:
php1 reads array database, contains integers - has following form:
[0, 70, 44, ...]
because number of entities contains varies, want able read , store whole array 1 cell of database - the solution must not disregard this, then.
php1 contains js, allows user on website, alters 1 of entities in array, makes it, e.g.;
[0, 75, 44, ...]
so far, good.
now want new array replace 1 in database, central goal fail achieve.
i'm working - isn't working:
php1 executes ajax magic, , sends array php2, works fine:
var arrayx = [0, 75, 44, ...]; var arrayy = json.stringify(arrayx); $.ajax({ url: 'php2.php', type: 'post', data: {arrayy: arrayy } });
php2 connects db, , attempts update 1 cell new array, means of following, doesn't work (!):
$arrayz = json_decode($_post['arrayy'], true); mysql_query("update userbase set db_column = $arrayz id=0", $con); mysql_close($con);
i've tried serializing $arrayz in php2, whole set of other solutions found on stackoverflow, none of them worked (or didn't apply them correctly of course) , i've found myself deadstruck...
i'm hoping talents me further own have!
i assume db_column holds string value, , such need quotes around $arrayz in sql string.
mysql_query("update userbase set db_column = '$arrayz' id=0", $con);
but fake51 pointed out, database schema flawed.
also, you're susceptible sql injection attack.
Comments
Post a Comment