Jump to content

Variable within Variable


adamjnz

Recommended Posts

[code]<?php echo $_POST[$row_products['productID']];?>[/code]

I am trying to get a variable within a variable. Basically the $_POST variable is a number that relates to productID in the products table. so for example if $row_products['productID'] was 1 then the echo would display the variable $_POST['1']

What is wrong with my code? It doesn't give me any errors it just doesnt come up with anything
Link to comment
https://forums.phpfreaks.com/topic/7000-variable-within-variable/
Share on other sites

[!--quoteo(post=363201:date=Apr 10 2006, 07:46 PM:name=akitchin)--][div class=\'quotetop\']QUOTE(akitchin @ Apr 10 2006, 07:46 PM) [snapback]363201[/snapback][/div][div class=\'quotemain\'][!--quotec--]
the problem is that you need to use braces, otherwise you are breaking the array syntax:

[code]$_POST[{$row_products['productID']}][/code]

give that a shot.
[/quote]

Got this error:

Parse error: parse error, unexpected '{', expecting ']' in .../testsite/profile/site/order.php on line 92
The original syntax is fine, the problem is that there is no index in the $_POST array that corresponds to the computed index.

Since what is contained in the $_POST array comes from names in a form, and those names can't be numeric, you can never have an index of "1" or "'1'". Please use the following code to dump the contents of the $_POST array when your script starts:
[code]<?php echo '<pre>' . print_r($_POST,true) . '</pre>'; ?>[/code] and see what is coming from the form and how it relates to your data.

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.