php gurus
- Started
- Last post
- 11 Responses
- fusionpixel
Question out there:
I have the following function in a Class:
my function(){
foreach($_POST as $key=>$value) {
$$key = $value;
}it works great if i echo $value, but if I use an external file to echo the $values, for some reason the external file cant find the values. is there any specific reason why? Do i need to set global for $value? which I am going to try right now.
Any advice would be greatly appreciated.
I am sure this has to do just with some scoping.
TIA.
- sherman0
sounds like a scope issue -
need more info
- unfittoprint0
instead of using it within a function you should just paste this line of code before any other php tags:
//includes $_POST, $_GET & $_COOKIE vars.
foreach ($_REQUEST as $key => $value) $$key = $value;
- cosmo0
print_r ($value);
see if that shows the array contents.
- cosmo0
try to return the $values from the function, see if that works.
my function()
{
foreach($_POST as key=>$value) {
$$key = $value;return $key;
}
- fusionpixel0
Ok, really quick explanation
this is a custom mail class so that I can use it with different forms.
the foreach request is in a function inside the class so I can call the functions in order.
Basicly this is what happens.
a>check user fill out the form
b> if they did, get all the form values
c> emailfor debugging in step c> I am postig the results to the browser so i can see it but its not a go, the foreach is working fine, if i echo the $values all of them echo fine. but when i want to use them to paste them as a part of another file, this all crumbles.
Is this still confusing?
If it is I can post the code in a PHP site.
TIA
- juanzo0
sherman was correct. this is a scope issue. the variables with $key as their variable name will only be set inside the function. when the function has finished executing it trashes the variables.
I see what you are trying to do, and I would strongly recommend not doing it, as it could be a security risk.
Check out:
- fusionpixel0
thanks
so what would be the proper way of doing it?
Any recommendations?
- ldww0
you need to use global vars, cause you are not passing anything into the function so it can not see it.
checkFormCrap(){
global $_POST;
foreach($_POST as $key=>$value) {
global $$key;if ($$key && !empty($$key){
$stopForm = 1;
}
return $stopForm;
}
- ldww0
email me if the code is crapped out, or help
- fusionpixel0
where is that place where you can post your code for people to review?
I have been googling but cant find anything, it seems like most places have their own now.
- fusionpixel0
Ok, I just got yelled at because my class is a mess
hahahaha
so anyways Im going back to the drawing board.
Thanks again all that took a minute to help.