0

Can you please show me ,how to pass the java script array to the php . is it this way.

$.post("php_mysql_write.php", {datageo: shapes});

and after ur php script .. but php say's

Warning: mysqli::prepare()
[mysqli.prepare]: Couldn't fetch mysqli in
C:\xampp\htdocs\blitz-gmap-editor-master\php_mysql_write.php on line
25

Fatal error: Call to a member function bind_param() on a non-object
in C:\xampp\htdocs\blitz-gmap-editor-master\php_mysql_write.php on
line 26 please. 

i used ur code

<?php $mysqli = new mysqli(/*args*/); $stmt =
$mysqli->prepare('INSERT INTO `tableName`(`columnName`) VALUES
(?)'); $stmt->bind_param('s', $json);

foreach($_POST['shapes'] as $value){   $json = json_encode($value); 
$stmt->execute(); } ?>

Dr.molle's answer on

How to save a Google maps overlay shape in the database?

iddamalgoda
  • 53
  • 1
  • 6

1 Answers1

0

You should:

JSON.stringify(array);

to encode your JavaScript array, then use:

$array=json_decode($_POST['jsondata']); 

in your PHP script to get the array.

Good luck!

Progo
  • 3,452
  • 5
  • 27
  • 44
  • Progo_can u help? pls see my code source "http://stackoverflow.com/questions/19614805/how-to-save-a-google-maps-overlay-shape-in-the-database" and i want to usedshapes in to mysql..did u mean before post i have to json encode..thanks 4 reply.. – iddamalgoda Feb 08 '14 at 02:32
  • @iddamalgoda Well, usually when making web software, you stick to _one_ programming language because communication between two languages gets tricky. I would recommend using AJAX. Also, you could try a javascript library called [php.js](http://phpjs.org). Personally, I would recommend making your program in only js, or only php. Good luck! – Progo Feb 08 '14 at 13:47