ejaboneta Posted October 6, 2009 Share Posted October 6, 2009 $e = '3'; $h = '4'; $str1 = "\$_POST[value$e][$h]"; eval("\$values = \"'$str1'\";"); echo $values; I'm trying to get is the value of $_POST[3][4]... but the eval is processing the $_POST[3] and leaving the [4]. So what I end up with is Array[4].... Any help? Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/ Share on other sites More sharing options...
salathe Posted October 6, 2009 Share Posted October 6, 2009 I'm trying to get is the value of $_POST[3][4]... Your code is trying a little too hard to be clever. Simplify. I may be missing some details that you post doesn't make clear but the following might work for you. $e = 3; $h = 4; $values = $_POST[$e][$h]; Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/#findComment-931800 Share on other sites More sharing options...
PFMaBiSmAd Posted October 6, 2009 Share Posted October 6, 2009 There is no reason to use eval() unless you are dynamically writing php code in a string someplace. All you are doing is evaluating array index names - $e = '3'; $h = '4'; $values = $_POST['value' . $e][$h]; Edit: And if you lose the word 'value' from the form field, you can do what salathe posted above. Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/#findComment-931803 Share on other sites More sharing options...
ejaboneta Posted October 6, 2009 Author Share Posted October 6, 2009 Well the post comes from a dynamic amount of values from a dynamic amount of fields. I was trying to keep it simple and just ask for what i needed but maybe I should be more detailed. I'm trying to allow my users to upload CSVs into our database. The problem is that the CSVs come from different places and so the field order and amount may be different. So I made a script that asks the user which columns in the CSV go into which column in the database. Then the next page, containing this code, formats the values to be inserted into the database. Hopefully this helps to be more clear.... ### FOR EACH ROW ### for($h=1; $h<$rowcount; $h++) { $values = $values . "$comma("; ##### GET VALUES ##### for($e=1; $e<$fieldcount; $e++) { $str1 = "\$_POST[$e][$h]"; eval("\$values = \$values . \"'$comma1$str1'\";"); $comma1 = ','; } $values = $values . ")"; $comma = ','; } the result should look like: ('Joe','Smith','1234 Main St'), ('Sally','Smith','431 North St') but I keep getting: ('Array[1]','Array[1]','Array[1]') ('Array[2]','Array[2]','Array[2]') Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/#findComment-931875 Share on other sites More sharing options...
sasa Posted October 6, 2009 Share Posted October 6, 2009 try <?php $values = array(); for($h=1; $h<$rowcount; $h++) { $val = array(); ##### GET VALUES ##### for($e=1; $e<$fieldcount; $e++) { $val[] = $_POST[$e][$h]; } $values[] = "('". implode("', '", $val) . "')"; } $values = implode(",\n",$values); ?> Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/#findComment-931914 Share on other sites More sharing options...
ejaboneta Posted October 6, 2009 Author Share Posted October 6, 2009 try <?php $values = array(); for($h=1; $h<$rowcount; $h++) { $val = array(); ##### GET VALUES ##### for($e=1; $e<$fieldcount; $e++) { $val[] = $_POST[$e][$h]; } $values[] = "('". implode("', '", $val) . "')"; } $values = implode(",\n",$values); ?> Perfect! For what its worth, I found a workarond by using eval() to change $_POST[3] to $post3, and then another eval on $post3[4]. But that works better! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/#findComment-931923 Share on other sites More sharing options...
mikesta707 Posted October 6, 2009 Share Posted October 6, 2009 this seems kind of pointless? It doesn't look like you need to use eval at all Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/#findComment-931925 Share on other sites More sharing options...
ejaboneta Posted October 6, 2009 Author Share Posted October 6, 2009 this seems kind of pointless? It doesn't look like you need to use eval at all I guess not. Well I'm not skilled enough to figure everything out on my own so I had to ask. Quote Link to comment https://forums.phpfreaks.com/topic/176739-solved-eval-problem/#findComment-931934 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.