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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.