Reputation: 53
I have create a array of user information and post it to another page for using.. but when i access it its not return any value.. only return A or r..
Can Any Buddy Help Me..
Create Array
<?php
$datas= array(
"Scountry"=>'ZA',
"SName"=>$SName,
"SCompany"=>$SCompany,
"SAddress"=>$SAddress,
"SAddress2"=>$SAddress2,
"SAddress3"=>$SAddress3,
"ssPlace"=>$fr[0],
"sZip"=>$fr[1],
"SPhone"=>$SPhone,
"SMobile"=>$SMobile,
"SEmail"=>$SEmail,
"SFex"=>$SFex
);
?>
My Post Form Is
<form action="submit.php" method="post" id="submit" name="submit">
<input type="hidden" name="clientdata" id="clientdata" value="<?php print_r($datas); ?>">
<input type="submit" value="Submit"/>
</form>
And My Access Code of submit.php
<?php
$clientdata = $_POST['clientdata'];
print_r($clientdata);
?>
when i print it with print
print_r($clientdata);
following result show
Array ( [Scountry] => ZA [SName] => name [SCompany] => adfsd [SAddress] => asdf [SAddress2] => adsf [SAddress3] => asdf [ssPlace] => adfddfd [sZip] => 0037 [SPhone] => 222222222 [SMobile] => 9926036842 [SEmail] => [email protected] [SFex] => 1111111111)
My Problem Is When I access Particular Value of array attribute its not print...
echo $clientdata->Scountry;
No Result Show
when i use
echo $clientdata[Scountry];
No Result Show
Can Any Body Help...
Upvotes: 2
Views: 879
Reputation: 33186
You have to use a string as a key for an array. The key has to be between "
, otherwise php will think you are looking for a constant.
echo $clientdata["Scountry"];
update:
You cannot just print_r data as a value from an input field, you will have to serialize it. this creates a json string from the array.
<input type="hidden" name="clientdata" id="clientdata" value="<?php echo json_encode($datas); ?>">
Now, in your code, you can just decode this json string to an object:
$clientdata = json_decode($_POST['clientdata']);
echo $clientdata->Scountry;
Upvotes: 2
Reputation: 5437
Implode your array and post it from the Form.
<form action="submit.php" method="post" id="submit" name="submit">
<input type="hidden" name="clientdata" id="clientdata" value="<?php implode('@@#@@',$datas); ?>">
<input type="submit" value="Submit" />
</form>
And on your PHP File:
<?php
$clientdata = $_POST['clientdata'];
$clientArray = explode('@@#@@',$clientdata);
echo '<pre>';
print_r($clientArray);
echo $clientArray['Secondary'];
?>
Upvotes: 0