Solved

using $_request

Posted on 2003-11-13
20
249 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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…

895 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

15 Experts available now in Live!

Get 1:1 Help Now