Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using $_request

Posted on 2003-11-13
20
Medium Priority
?
258 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 
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 84 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

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

730 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