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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.