cobalt30 Posted January 9, 2010 Share Posted January 9, 2010 I have a grid array that I am using with a form that when it hits the currently named test.php it logs in and grabs 3 coordinates (i.e. B1, D3, etc). which come back as XML fields "challenge1", "challenge2", and "challenge3" and then has to match up the value in the grid array and pass the correct value down to my post fields as "response1", "response2", "response3". However, nothing I'm trying will get the values out to then post. I'm sure my coding is wrong, but I cannot figure out the right syntax to make it work. Here is part of my grid array: $grid_array = array("A1" => "V", "A2" => "2", "A3" => "1", "A4" => "N", "A5" => "7", "B1" => "H", "B2" => "9", "B3" => "3", "B4" => "T", "B5" => "J", "C1" => "9", "C2" => "2", "C3" => "2", "C4" => "6", "C5" => "Y", "D1" => "N", "D2" => "1", "D3" => "R", "D4" => "8", "D5" => "K"); I tried coding this, which is completely wrong, but maybe I'm on to something at least?: foreach ($grid_array as $key => $value) { $grid_array['$xdoc1->challenge1'] = '$response1'; $grid_array['$xdoc1->challenge2'] = '$response2'; $grid_array['$xdoc1->challenge3'] = '$response3'; } ($xdoc1 is the XML return as a SimpleXMLElement, by the way) But this returns an error of Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting T_PAAMAYIM_NEKUDOTAYIM Am I at least on the right track? If not, any ideas on how I can code this to pull out the values that are returned from the first hit and have it pass the appropriate values to the second hit? Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/ Share on other sites More sharing options...
premiso Posted January 9, 2010 Share Posted January 9, 2010 Using variables in single quotes take them literally. Try using: $grid_array[$xdoc1->challenge1] = $response1; $grid_array[$xdoc1->challenge2] = $response2; $grid_array[$xdoc1->challenge3] = $response3; Should give you correct results. Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991456 Share on other sites More sharing options...
cobalt30 Posted January 9, 2010 Author Share Posted January 9, 2010 What about the foreach statement? I'm still getting the Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting T_PAAMAYIM_NEKUDOTAYIM. So I can't tell if it works or not. Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991474 Share on other sites More sharing options...
Zane Posted January 9, 2010 Share Posted January 9, 2010 Exactly which line are you getting this error on? Because.. short of what premiso has already said, I see nothing wrong with your code Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991480 Share on other sites More sharing options...
cobalt30 Posted January 9, 2010 Author Share Posted January 9, 2010 It's on this line: foreach ($grid_array as $key => $value) { I Googled it and it referenced something about double colons, but when I changed the => to :: it gave an error about the parentheses, so I'm not sure what needs done to this. Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991481 Share on other sites More sharing options...
Zane Posted January 9, 2010 Share Posted January 9, 2010 most likely the error is a line or so above that one. The line you posted looks fine. . nothing wrong Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991493 Share on other sites More sharing options...
cobalt30 Posted January 9, 2010 Author Share Posted January 9, 2010 The grid array is what is above this line. It is formatted just like this: $grid_array = array("A1" => "V", "A2" => "2", "A3" => "1", "A4" => "N", "A5" => "7", "B1" => "H", "B2" => "9", "B3" => "3", "B4" => "T", "B5" => "J", "C1" => "9", "C2" => "2", "C3" => "2", "C4" => "6", "C5" => "Y", "D1" => "N", "D2" => "1", "D3" => "R", "D4" => "8", "D5" => "K"); foreach ($grid_array as $key => $value) { $grid_array[$xdoc1->challenge1] = $response1; $grid_array[$xdoc1->challenge2] = $response2; $grid_array[$xdoc1->challenge3] = $response3; } Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991497 Share on other sites More sharing options...
Zane Posted January 9, 2010 Share Posted January 9, 2010 $grid_array = array( "A1" => "V", "A2" => "2", "A3" => "1", "A4" => "N", "A5" => "7", "B1" => "H", "B2" => "9", "B3" => "3", "B4" => "T", "B5" => "J", "C1" => "9", "C2" => "2", "C3" => "2", "C4" => "6", "C5" => "Y", "D1" => "N", "D2" => "1", "D3" => "R", "D4" => "8", "D5" => "K" ); foreach ($grid_array as $key => $value) { $id1 = $xdoc1->challenge1; $id2 = $xdoc1->challenge2; $id3 = $xdoc1->challenge3; $grid_array[$id1] = $response1; $grid_array[$id2] = $response2; $grid_array[$id3] = $response3; } Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991501 Share on other sites More sharing options...
cobalt30 Posted January 9, 2010 Author Share Posted January 9, 2010 Now I get this: Warning: Illegal offset type in /home/content/html/test.php on line 77 Warning: Illegal offset type in /home/content/html/test.php on line 78 Warning: Illegal offset type in /home/content/html/test.php on line 79 These 3 errors correspond to these lines: $id1 = $xdoc1->challenge1; $id2 = $xdoc1->challenge2; $id3 = $xdoc1->challenge3; I really appreciate your help with this. Any ideas? I am using PHP5, if that makes a difference. Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991509 Share on other sites More sharing options...
Zane Posted January 9, 2010 Share Posted January 9, 2010 what do $xdoc1->challenge1 2 and 3 return anyway. Are you even sure they exist? Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991511 Share on other sites More sharing options...
cobalt30 Posted January 9, 2010 Author Share Posted January 9, 2010 This is what comes back on the first hit from the XML: [challenge1] => A5 [challenge2] => H4 [challenge3] => I5 It generates different coordinates each time, but this was the one that came back on my test with the code you provided me. Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991512 Share on other sites More sharing options...
cobalt30 Posted January 9, 2010 Author Share Posted January 9, 2010 Also those 3 lines of the Illegal offset type error repeat the same number of times as the total number of coordinates, like it is trying to get every value and not just the one returned, if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991513 Share on other sites More sharing options...
cobalt30 Posted January 9, 2010 Author Share Posted January 9, 2010 Ok, I've switched it back to just this: foreach ($grid_array as $key => $value) { $grid_array['$xdoc1->challenge1'] = '$response1'; $grid_array['$xdoc1->challenge2'] = '$response2'; $grid_array['$xdoc1->challenge3'] = '$response3'; } No errors on this side, but the values still do not seem to be posting. Here is the code where I'm trying to post, and maybe my syntax here is wrong as well?: curl_setopt($ch_pay, CURLOPT_POSTFIELDS, array ('response1'=>$_POST[$response1], 'response2'=>$_POST[$response2], 'response3'=>$_POST[$response3])); curl_setopt($ch_pay, CURLOPT_RETURNTRANSFER, 1); Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-991757 Share on other sites More sharing options...
cobalt30 Posted January 10, 2010 Author Share Posted January 10, 2010 I figured it out. I actually didn't need to try to pull the values before the POST. Here is the syntax I used in my POST array that worked: 'response1'=>$grid_array["".$xdoc1->challenge1.""], 'response2'=>$grid_array["".$xdoc1->challenge2.""], 'response3'=>$grid_array["".$xdoc1->challenge3.""] Thanks for all your help, it definitely helped lead me in the right direction and saved me a lot more debugging time. Quote Link to comment https://forums.phpfreaks.com/topic/187782-grabbing-values-from-an-array-for-posting/#findComment-992301 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.