php - Pass Jquery Array to MySql -


i have been trying of examples given on passing array generated jquery php store in mysql db on php side "array".

i writing code bingo game. jquery generates , array called "drawarray" should stored in database. example:

 ["n37", "g72", "o47", "i43", "n26", "g65", "i62", "n14", "b69", "g67", "i63", "g09", "g01", "g52", "n57", "b42", "n21", "i54", "n21", "n13", "n10", "n01", "n71", "i21", "o01", "g72", "o27", "g32", "o31", "b19", "o34", "i69", "o49", "o29", "g52", "o26", "i34", "i66", "i68", "i60"] 

i have tried ajax, jquery.post , either way either noting on php side or "array"

here jquery:

 $("#draw").click(function() {         drawnumbers();         console.log(drawarray);          $.ajax({             url: "includes/dealerpicks.php",             type: 'post',             data: {'drawarray[]' : drawarray},             datatype: "json",             async: false         });        }); 

and on php side:

    //post data $dealernums = $_post['drawarray'];  echo $dealernums . "<br><br>";  $sql="insert drawings (dealerpicks)                 values                 ('$dealernums')";                  if (!mysqli_query($conn, $sql))                     {                         die('error: ' . mysqli_error($conn));                     }                 echo "1 record added";                 mysqli_close($conn)   ?> 

so of course need store of dealer numbers db later use when drawing out bingo card. figured store , of drawings array in db referenced later in php.

why getting "array" value?

$dealernums array. using string. should solve problem, adding couple of safety checks:

$dealernums = $_post['dealernums'];  if (!is_array($dealernums)) {   // handle error  }  //escape_string avoid sql injection $dealerstr = $conn->escape_string(join(',', $dealernums));  $sql="insert drawings (dealerpicks)                 values                 ('$dealerstr')"; 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -