1

I have an array in javascript that I want to post to php to store into oracle varchar2. I would like to know how to fetch this array in php. For now I always have a string [object Object] instead of the array in oracle. Im using JQuery $.post to send the variable to php like this:

function savePolygons(){
    $.get('oracle_deletePolygons.php');
    for (var i = 0; i < createdShapes.length; i++){
        var nom_zone  = escape(document.getElementById('nom_zone_' + createdShapes[i].id).value);
        var couleur = escape(createdShapes[i].fillColor);
        var code_cs = escape('711');
        var shapeid_export = escape(createdShapes[i].id);
        var geometry = createdShapes[i].getPath();
        alert(geometry)
        var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
        $.get(url1);
    }
}

in php:

<?php
require("oracle_dbinfo.php");
sleep(5);
$nom_zone =$_GET['nom_zone'];
$shapeid_export = $_GET['shapeid_export'];
$code_cs = $_GET['code_cs'];
$couleur = $_GET['couleur'];
$geometry = $_GET['geometry'];

$conn = oci_connect($username, $password, $database);
$query = oci_parse($conn, 'INSERT INTO test1 (nom_zone, shapeid, code_cs, couleur, geometry) VALUES (:nom_zone, :shapeid_export, :code_cs, :couleur, :geometry)');

oci_bind_by_name($query, ":nom_zone", $nom_zone);
oci_bind_by_name($query, ":shapeid_export", $shapeid_export);
oci_bind_by_name($query, ":code_cs", $code_cs);
oci_bind_by_name($query, ":couleur", $couleur);
oci_bind_by_name($query, ":geometry", $geometry);

oci_execute($query);
oci_commit($conn);
?>

the var geometry is an array of coordinates of each vertices of the polygon.

1
  • Why are you using $.post() then why are you building a parameter string as used for GET? Commented Dec 20, 2012 at 21:26

1 Answer 1

1

Just use $.get() if your not posting any data to the url:

$.get('oracle_deletePolygons.php');

Please refer to jQuery.get()

Also note this should most likely be using $.get() because your just sending querystrings:

var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
$.post(url1);

Try this instead:

var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
$.get(url1);

Example of posting data using $.get():

$.get('oracle_savePolygons.php', {
    'num_zone' : nom_zone,
    'couleur' : couleur,
    'code_cs' : code_cs,
    'shapeid_export' : shapeid_export,
    'geometry' : geometry
}, function (data) {
  //Success callback if you need it
});
Sign up to request clarification or add additional context in comments.

2 Comments

In fact the data are not posted in oracle_deletePolygons.php, but in oracle_savePolygons.php. oracle_deletePolygons.php just delete all records of the oracle table.
Ok, so I cant use querystrings for array. How to post it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.