ornclo Posted January 30, 2009 Share Posted January 30, 2009 I solved one problem, and have another. I am no expert with PHP, so any help is good. I have a form with questions with a radio and check boxes. Here is a exert from my form: <table class="part3"" align="center"> <tr> <td colspan="2"> <div align="center" class="QuesTxt">How did you find this site?</div> </td> </tr> <tr> <td> <div class="options"><input type="checkbox" name="hear[ ]" value="@ Church">@ church</div> </td> <td> <div class="options"><input type="checkbox" name="hear[ ]" value="From a friend">From a friend</div> </td> </tr> <tr> <td> <div class="options"><input type="checkbox" name="hear[ ]" value="Google">Google</div> </td> <td> <div class="options"><input type="checkbox" name="hear[ ]" value="Other">Other</div> </td> </tr> </table> In my PHP code, I have: $Church = trim(stripslashes($_POST['visit'])); $About = trim(stripslashes($_POST['hear'])); $Ask = trim(stripslashes($_POST['help'])); My question is simple. Is this how I am suppose to write the code for an array in the PHP to have it read it correctly? Please let me know. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/ Share on other sites More sharing options...
sKunKbad Posted January 30, 2009 Share Posted January 30, 2009 none of the code that you have shown has an array. Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-750278 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 none of the code that you have shown has an array. 1. The POST data sent from the form is an array 2. $_POST['hear'] is an array of positive checkbox results @ornclo That's not quite right; <?php foreach($_POST['hear'] as $value){ $About[] = trim(stripslashes($value)); } Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-750279 Share on other sites More sharing options...
ornclo Posted January 30, 2009 Author Share Posted January 30, 2009 Forgot to add... When I fill out the form, I get 4 error's, but then I get the ok.html. When I get the email, I get the forms part that I filled out, but I get "Array" on the email. Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-750288 Share on other sites More sharing options...
ornclo Posted January 30, 2009 Author Share Posted January 30, 2009 the $value part - is that just something that I can define??? like I have visit, do I just use $visit??? Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-750294 Share on other sites More sharing options...
ornclo Posted January 30, 2009 Author Share Posted January 30, 2009 To Gevans: You posted: <?php foreach($_POST['hear'] as $value){ $About[] = trim(stripslashes($value)); } I followed your advice and added that to my code. for each of the three selections that have either a radio or checkbox, I have done the following: foreach ($_POST['visit'] as $visit) { $Church[] = trim(stripslashes($visit)); foreach ($_POST['hear'] as $hear) { $About[] = trim(stripslashes($hear)); foreach ($_POST['help'] as $help) { $Ask[] = trim(stripslashes($help)); When I run the form and hit submit, I now get an error returned: Parse error: parse error, unexpected $ in /home/content/a/c/h/achurch4life/html/emailme.php on line 126 On line 126 of my code, is blank. It is the line just after the closing </html> tag. Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-750503 Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 You're not closing any of your foreach conditional statements.... You need to add the closing curly bracket } Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-750533 Share on other sites More sharing options...
ornclo Posted January 31, 2009 Author Share Posted January 31, 2009 yea, I figured that out. But that didn't help. However, I have found a site where it explains the foreach a little more. Forgive me for ignorance in this matter. I just wish to solve this and be on my way. Do I need to declare the array elements in the form as well as in the php?? As per example of the code below, do I need to assign each array a number or varaialbe or name? This is in the html form itself... table class="part2" align="center"> <tr> <td rowspan="2"> <div class="QuesTxt">Have you ever attended Church Of God?</div> </td> <td> <div class="options"><input type="radio"name="visit[1]" checked value="Yes">Yes</div> </td> </tr> <tr> <td> <div class="options"><input type="radio"name="visit[2]" value="No">No</div> </td> </tr> </table> from here, I question the following. Do I need to define the array in the PHP? $Church = array('1' => 'Yes', '2' => 'No'); foreach ($_POST['visit'] as $value) { $Church[] = trim(stripslashes($value)); } Please let me know so I can be on my way... Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-751384 Share on other sites More sharing options...
ornclo Posted January 31, 2009 Author Share Posted January 31, 2009 finally got it to work. You code: foreach ($_POST['visit'] as $visit) { $Church[] = trim(stripslashes($visit)); foreach ($_POST['hear'] as $hear) { $About[] = trim(stripslashes($hear)); foreach ($_POST['help'] as $help) { $Ask[] = trim(stripslashes($help)); I just needed to take off the [] of the $Church[]. Thank you for your help... Quote Link to comment https://forums.phpfreaks.com/topic/143059-php/#findComment-751560 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.