Jump to content

PHP


ornclo

Recommended Posts

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.

 

Link to comment
Share on other sites

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));
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.