adamjnz Posted April 10, 2006 Share Posted April 10, 2006 [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 More sharing options...
akitchin Posted April 10, 2006 Share Posted April 10, 2006 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. Link to comment https://forums.phpfreaks.com/topic/7000-variable-within-variable/#findComment-25409 Share on other sites More sharing options...
adamjnz Posted April 10, 2006 Author Share Posted April 10, 2006 [!--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 https://forums.phpfreaks.com/topic/7000-variable-within-variable/#findComment-25410 Share on other sites More sharing options...
kenrbnsn Posted April 10, 2006 Share Posted April 10, 2006 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 https://forums.phpfreaks.com/topic/7000-variable-within-variable/#findComment-25503 Share on other sites More sharing options...
akitchin Posted April 10, 2006 Share Posted April 10, 2006 sorry, for my post, it should have been:[code]$_POST["{$row['product_id']}"][/code]but ken is right. check what's in $_POST first. Link to comment https://forums.phpfreaks.com/topic/7000-variable-within-variable/#findComment-25674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.