Solved

using $_request

Posted on 2003-11-13
20
248 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
  • 8
  • 5
  • 4
  • +1
20 Comments
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
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
Comment Utility
comment: try putting $tmp into " " quotes
0
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
i don't think that should make a difference, vince

loz
0
 
LVL 1

Author Comment

by:aot2002
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:DoppyNL
Comment Utility
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
Comment Utility
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
Comment Utility
>>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
Comment Utility
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
Comment Utility


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
Comment Utility
as soon as i get the correct answer i will ask for it changed
0
 
LVL 1

Author Comment

by:aot2002
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now