Identifying array elements PHP and AJAX

I have managed to get the correct response to my php page which is listing an array.

I believe that I am passing in AJAX a array string which I can print using $_POST. The problem I am having NOW is when I try to loop through the array to identify its contents which I need to make insertions into a database.

[php]<?php

if (ISSET($_POST['data'])) 
{ echo "TRUE./n"; 
}ELSE{ 
echo "False./n"; 
} 

// look at array var_dump($_POST['data']); 

// identifies an array property or key / name pair 

var_dump($_POST['data'][1]["ask"]); 

// foreach loop: to try to identify array elements 

foreach($data as $user) 
{ echo $user['ask']; } 

?>[/php]
I receive a notice undefined variable data. What am I doing incorrectly?.

sending script

[event]

for (i = 1; i<3; i++)
{

// I collect values for check_a and check_b via radio button responses above

array.push({id:i, ask:check_a, description:check_b});

}

$.ajax
({
type: ‘POST’,
url: ‘out.php’,
data: {data: array},
success: function(msg)

{
alert(msg);
}

});


Your foreach loop is aliasing $data as $user, but you never assigned a value to $data. So, ‘data’ doesn’t exist.

are you indicating that I need to do some thing like;

$data = ($_POST[‘data’]);

Sorry I am new at this.

[php]
foreach($_POST[‘data’][1][“ask”] as $user)
{
echo ‘

’;
print_r($user);
echo ‘
’;
}
[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service