0

I have some number which are generated randomly . I need to get these numbers on server side i.e.$POST['number_array'].This "number_array" should include all the randomly generated numbers .Can anybody suggest me some way to do this. I am using PHP , Jquery , Javascript

3
  • Do you mean: $_POST['number_array']? Commented Aug 11, 2011 at 12:06
  • I don't know what did you do in client side: how about your html, javascript? Commented Aug 11, 2011 at 12:08
  • on client side i already have an array which has these number.. I just need to send this to server side . I am using javascript on client side Commented Aug 11, 2011 at 12:16

4 Answers 4

1

your GET/POST request should look like this:

number_array[]=1&number_array[]=2&number_array[]=5
Sign up to request clarification or add additional context in comments.

Comments

0

Put []s after the name of the form element.

<input type="text" name="number_array[]" />
<input type="text" name="number_array[]" />
etc.

Then you can access the variables like so:

$number_array = $POST['number_array'];
$number_array[0];

2 Comments

But how do i insert those numbers in random[]
You said you already have "some number which are generated randomly". Just put them into the number_array[] textboxes using JavaScript.
0

If this is an ajax call, you can do it with jquery:

$.post("test.php", { 'number_array[]': [65, 45] }, function(data) {
  alert("Data Loaded: " + data);
}););

EDIT: both 'number_array[]': [65, 45] and 'number_array': [65, 45] works fine, and " around javascript arrays are optional

1 Comment

I don't think that your fucntion is correct: You must number_array: ["65", "45"], because ["65", "45"] is array.
0

Let me summary what you need:

Client side with javascript

<script>
    //If you have an array with 3 items with random value
    var arrInt = [Math.random(),Math.random(),Math.random()];
    //If you want to send it to file yourscript.php
    //1. Using GET mothod
    /*
    $.get(
        'yourscript.php',        
        {
            number_array: arrInt
        }
    );
    */
    //2. Using POST method:
    $.post(
        'yourscript.php',        
        {
            number_array: arrInt
        }
    );
</script>

Server side with PHP:

<?php
    //$arrInt = $_GET['number_array'];//If using GET
    $arrInt = $_POST['number_array'];//If using POST
    print $arrInt[0];
    print $arrInt[1];
    print $arrInt[2];
?>

1 Comment

exactly this is how i need.. let me try this

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.