Solved

using $_request

Posted on 2003-11-13
20
253 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:aot2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
  • +1
20 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9737993
hi,

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

loz
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9737998
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]);
}
0
 
LVL 1

Author Comment

by:aot2002
ID: 9740978
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:lozloz
ID: 9742320
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
0
 
LVL 1

Accepted Solution

by:
vincevincevince earned 21 total points
ID: 9742583
comment: try putting $tmp into " " quotes
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9742663
i don't think that should make a difference, vince

loz
0
 
LVL 1

Author Comment

by:aot2002
ID: 9742667
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
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9742764
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
0
 
LVL 1

Author Comment

by:aot2002
ID: 9743613
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
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9745648
>>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?
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9745656
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/
0
 
LVL 1

Expert Comment

by:vincevincevince
ID: 9745942
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
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9745945
>>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.
0
 
LVL 1

Expert Comment

by:vincevincevince
ID: 9746034
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.
0
 
LVL 1

Author Comment

by:aot2002
ID: 9749834


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<
><
0
 
LVL 1

Author Comment

by:aot2002
ID: 9749936
as soon as i get the correct answer i will ask for it changed
0
 
LVL 1

Author Comment

by:aot2002
ID: 9750033
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
0
 
LVL 1

Author Comment

by:aot2002
ID: 9750054
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
0
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9750258
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.
0
 
LVL 1

Author Comment

by:aot2002
ID: 9750731
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question