using $_request

I want to use a declare the number when requesting the variables from a form example

$primarykey="3"
$tmp="description".$primarykey;
$itemdescription = $_REQUEST[$tmp];

$primarykey="90"
$tmp="description".$primarykey;
$itemdescription = $_REQUEST[$tmp];

how can i use primarykey as a dynamic variable to create the request i want to get from the incoming form?

hopefully you'll understand my jargon talk!

Thanks
LVL 1
aot2002Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lozlozCommented:
hi,

i don't really know what you mean.. where's your primary key coming from? what do you want from the script?

loz
DoppyNLCommented:
first of all, $_REQUEST will only contain values that were sent from the form to the server; you have to work with that set of data and you can't "ask" the user to fill in certain values when processing the form.

But you probably allready know that, so I've got absolutely no idea why I said that.


you could do something like this:

for ($primarykey = 1; $primarykey < 100; $primarykey++)
{
     print($_REQUEST['description' . $primarykey]);
}
aot2002Author Commented:
i tried that doesnt seem to work maybe im missing something here?
but yes DoppyNL thats the idea of what i want exactly except its not working
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

lozlozCommented:
is your PHP version before 4.1.0? if so you need to use $HTTP_POST_VARS or $HTTP_GET_VARS depending on your form's method. to test what's working, simply have your processing page as: print_r($_REQUEST); print_r($_POST); print_r($_GET); will show you a lot of info about what is coming through to the script. if you give us the results from this and some of your code then we might be able to help more

loz
vincevincevinceCommented:
comment: try putting $tmp into " " quotes

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lozlozCommented:
i don't think that should make a difference, vince

loz
aot2002Author Commented:
Comment from lozloz
I know how to use requests and they are supported in my version or else i wouldn't have posted the question.

vincevincevince
thanks
lozlozCommented:
on the other hand i've been wrong before..

but i still don't see how putting the variable in quotes changes the index, it would be treated as a string either way?

loz
aot2002Author Commented:
true good point and i jumped the gun sorry for the reaming lozloz it didnt work and i thought it did?

maybe i should pass a $$ type variable
DoppyNLCommented:
>>i tried that doesnt seem to work maybe im missing something here?
>>but yes DoppyNL thats the idea of what i want exactly except its not working
are you getting an error message?
what is going wrong?
DoppyNLCommented:
shouldn't make a difference at all if you put $tmp in "" or not; only difference is that your script will run SLOWER when you add that!


If you didn't mean to accept that answer you can ask to "unaccept" the answer in CS; then you will be able to accept another comment (or comments) as an answer once you get your answer.
CS: http://www.experts-exchange.com/Community_Support/
vincevincevinceCommented:
examples (working currently from my site)
$_REQUEST["comments_$r[2]_$uid"]
$_REQUEST[$varname]

i have a suspicion that your problem lies in the value of $tmp not being the same as the form field value.  to check this:
1) echo $tmp from your script and note it down
2) change your form action to "mailto:your@address.com" and it will give you the exact raw passed values from that form - ensure $tmp is the same as the passed value name in that email

best of luck, sorry my previous answer didn't work out
DoppyNLCommented:
>>2) change your form action to "mailto:your@address.com" and it will give you the exact raw passed values from that form - ensure $tmp is the same as the passed value name in that email

just do this in the receiving page:

print_r($_POST);
or
print_r($_REQUEST);

to print out the contents of an entire array; no need to use emails here.
vincevincevinceCommented:
DoppyNL, that's a good approach, but dependant upon PHP correctly rendering the variables, and that the values have not been changed previously within the script etc...  Hence my preference for grabbing it directly from the browser.

Either approach has merit.
aot2002Author Commented:


heres my code unleashed

<input type="text" value="4" size="3" name="qty3">

the form text to pass

$primarykey =$_REQUEST['primarykey']; //get the primary key only using number 3 right now
$tmp="qty".$primarykey; //heres what creates the form name
echo "Should be this >".$tmp."< <br>";  //heres what is should have passed to request
echo ">".$_REQUEST[$tmp]."<"; //show the damn request


on screen is this

Should be this >qty3<
><
aot2002Author Commented:
as soon as i get the correct answer i will ask for it changed
aot2002Author Commented:
i looked at some old could which was probably a previous version of php
and heres the code im not sure if its still suportted

$tmp="qty$primarykey";
echo "Should be this >".$$tmp."< <br>";  
echo ">".$_REQUEST[$$tmp]."<";

it uses the double $$ anyone know if this has changed in versions i tried looking it up on the net but no luck.

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=php+using+%24%24+dynamic+variable
aot2002Author Commented:
i found the answer to be a </form> not covering the other text box's ouch
take my advice dont program at 4am in the morning.....

since vincevincevince had it right on the money again i'll leave the points where thier at !

>>i have a suspicion that your problem lies in the value of $tmp not being the same as the form >>field value.  to check this:

thanks for the obvious vince!!!


DoppyNL you pressed great info to me how can i send you points????
let me know
DoppyNLCommented:
easiest way is to post a new question with the title
"Points for: DoppyNL"
in there a link to this question

and post a link here to the "points for" question.

When I posted in that question you can accept that as an answer.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.