-2

I'm getting closer. I have a form that want to submit to a PHP file for processing and updating a MySQL db and then update a div. I can send the data to my PHP file and see it but not sure how to access it so it is useful.

from my JS

var str = $("form").serialize();
xmlhttp.open("GET","concessions_write.php?"+str,true);
xmlhttp.send();

sends this to my PHP file

concessions_write.php?btn%5B%5D=button01&itm%5B%5D=Hot+Dog&prc%5B%5D=1.00&id%5B%5D=1&btn%5B%5D=button02&itm%5B%5D=Popcorn&prc%5B%5D=1.00&id%5B%5D=3&btn%5B%5D=button03&itm%5B%5D=Combo&prc%5B%5D=3.50&id%5B%5D=2&btn%5B%5D=button04&itm%5B%5D=Nabs&prc%5B%5D=0.50&id%5B%5D=4&name=&message= 

in my PHP file a

print_r($_GET);

gives

Array (
    [btn] => Array (
        [0] => button01
        [1] => button02
        [2] => button03
        [3] => button04 
    )
    [itm] => Array (
        [0] => Hot Dog
        [1] => Popcorn
        [2] => Combo
        [3] => Nabs
    )
    [prc] => Array (
        [0] => 1.00
        [1] => 1.00
        [2] => 3.50
        [3] => 0.50
    )
    [id] => Array (
        [0] => 1
        [1] => 3
        [2] => 2
        [3] => 4
    )
    [name] =>
    [message] =>
)

This is the info I need. Each entry has 4 parts - btn, itm, prc and id and I currently have 4 entries. Just not sure how to break it down to usable arrays so I can write the data back to the db.

Look at parse_str but can't seem to get it to work.

Ideas? Also any idea where name and message might be coming from? No form elements with this.

3
  • This question is vague. You have your request, and you know how to get your data from it, and now you want... what? Commented Dec 29, 2012 at 18:04
  • 1
    Why are you creating an XMLHttpRequest manually? The jQuery $.get() function would make this simpler. Commented Dec 29, 2012 at 18:05
  • Related to OP's previous questions here, here and here. Commented Dec 29, 2012 at 19:08

2 Answers 2

1

if you know the format of the data you can do this after you collect the $_GET as array():

$_GET['btn']['0'];

The name and meesage have to be coming form form input names.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. As the length is variable is there an easy way to get the length of the array?
Use count or sizeof. Basically the same. $length = sizeof($_GET['btn']);
0

Seems to me you just need a for loop:

for ($i = 0; $i < 3; $i++) {
    $btn = $_GET['btn'][$i];
    $itm = $_GET['itm'][$i];
    $prc = $_GET['prc'][$i];
    $id = $_GET['id'][$i];

    // Sanitise and save these values here
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.