Jump to content

Archived

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

adamjnz

Variable within Variable

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
sorry, for my post, it should have been:

[code]$_POST["{$row['product_id']}"][/code]

but ken is right. check what's in $_POST first.

Share this post


Link to post
Share on other sites

×

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.