Hatdrawn Posted June 11, 2009 Share Posted June 11, 2009 I'll try to explain best I can, let me know if I'm not clear please. I created an array $arr_email = array(); then I have an if statement that does several things, everything works, but the focus is adding to the array $arr_email. if($_POST['Submit_Auto'] || !$_POST['Email_Auto']){ echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post"><table class="verify"><tr><td><h3 style="margin-bottom:5px;">Auto Insurance Form</h3></td></tr><tr><td style="margin:0;padding:0;font-size:smaller;font-style:italic;">Please verify your information</td></tr>'; foreach($_POST as $var => $value) { if(in_array($var, $arr_auto)){ echo '<tr>'; echo '<td class="output">'.$var . '</td><td><span class="userInput">' . $value . '</span></td>'; $arr_email[$var] .= $value; } echo '</tr>'; } print_r($arr_email); echo '<tr><td><input type="button" value="Go Back" onclick="history.go(-1);return true;"/></td><td><input type="submit" name="Email_Auto" value="Request Quote"/></td></tr></table></form>'; } I have a page that displays the information from a form on the page before. This works fine. I added a submit button to accept this information and send it. The submit button is in a form that has the action $_SERVER['PHP_SELF'] the name of the submit button is Email_Auto. Now i have a following else/if statement where I try to access $arr_email because I use it to create the body of my email. else if($_POST['Email_Auto']){ $to = "[email protected]"; $headers = "From: Think!nsure Auto Insurance Form"; $subject = "Auto Insurance Quote Request"; $body = "The user submitted the following:\n\n"; foreach($arr_email as $var => $value){ if(in_array($var, $arr_auto)){ $body .= sprintf("%20s : %s\n",$var,$value); } } if (mail($to, $subject, $body, $headers)) { echo("<p>Message successfully sent!</p>".$body); print_r($arr_email); } else { echo("<p>Message delivery failed...</p>".$body); print_r($arr_email); } } The print_r($arr_email); in the if statement shows me what I want and the others do not, so it seems that once I hit the Email_Auto submit it clears the array. I might have a very wrong idea of what's going on here. I get the emails, but they only have the default body. Please help and please forgive me if I'm a complete idiot. I can post all the php if necessary but this is all the relevant php. Thanks, Hatdrawn Quote Link to comment https://forums.phpfreaks.com/topic/161840-cant-access-array/ Share on other sites More sharing options...
gijew Posted June 11, 2009 Share Posted June 11, 2009 Not 100% here but try replacing: <?php $arr_email[$var] .= $value; ?> with <?php $arr_email[$var] = $value; ?> Quote Link to comment https://forums.phpfreaks.com/topic/161840-cant-access-array/#findComment-853862 Share on other sites More sharing options...
Hatdrawn Posted June 11, 2009 Author Share Posted June 11, 2009 Thanks but no. I need it to keep adding values, that will just repeatedly replace the values. Quote Link to comment https://forums.phpfreaks.com/topic/161840-cant-access-array/#findComment-853871 Share on other sites More sharing options...
Hatdrawn Posted June 11, 2009 Author Share Posted June 11, 2009 Is the question I'm asking not clear? Or is the problem not clear? Or can no one figure it out? Any kind of help would be useful. Quote Link to comment https://forums.phpfreaks.com/topic/161840-cant-access-array/#findComment-853902 Share on other sites More sharing options...
J.Daniels Posted June 11, 2009 Share Posted June 11, 2009 With the two pieces of code you have provided, and assuming they are they in the same if/else statement, $arr_email only gets added to if $_POST['Submit_Auto'] is true and $_POST['Email_Auto'] is false. So when Email_Auto is submitted, it goes into the elseif statement where you are only trying to read from the $arr_email array. Quote Link to comment https://forums.phpfreaks.com/topic/161840-cant-access-array/#findComment-853903 Share on other sites More sharing options...
Hatdrawn Posted June 11, 2009 Author Share Posted June 11, 2009 Thank you. Sending it to a third page should fix the problem so I don't have to add those if statements. Quote Link to comment https://forums.phpfreaks.com/topic/161840-cant-access-array/#findComment-853917 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.