Dynamic Checkboxes AARGH!


#1

I’m new to PHP and MySQL and may have bit off more than I wanted to.
I’ve only been at it for a few weeks. Well actually I started 4 weeks ago but who’s counting.

I decided to set up a voting site for a dance organization I belong to. So far I have the login and profile stuff set up for the users with email authentication similar to the way most sites validate users.

Besides the users table and a couple other miscellaneous tables I have…

One table that contains the list of dances this table can contain from 5 to “x” dances, but probably not more than 50.
I also have a table that will contain the dances that each user votes on.

In my example (video)… there are 15 dances and each user can vote on 5.

The tables…
dance_list: | dance_name | choreographer | level |
vote_list: | voter_email | dance_selection |

I got the code to work that displays the dances from the dance_list and if the user has previously voted, the list is compared to the choices in the vote_list and the users previous choices are ‘checked’.

Now my problem is I don’t seem to be able to get any new choices the user may chose and put them in the database.

I guess I need to be able to see a var_dump of the choices but I haven’t been able to do that.

Any help would be appreciated.

Here’s the code I’m using to display the choices

<?php foreach ($articles as $article): ?> <-- *** THIS LOOPS THROUGH THE "CHOICES LIST ***
  <?php $isChecked = NULL; ?>
  <?php foreach ($articles2 as $article2): ?> <-- *** THIS LOOPS THROUGH THE "VOTED" LIST ***
    <?php if ($article['dance_name'] === $article2['dance_selection']): ?>					
       <?php $isChecked = 'checked'; ?>
    <?php endif; ?>
  <?php endforeach ?>
  <form action="#" method="post">
    <?php if($formSubmitBtn === false): ?>
      <div style="margin: 0px 210px 20px; text-align:left;">
        <button type="submit" name="voteBtn" class="btn btn-primary">Submit</button>
      </div>
      <?php $formSubmitBtn = true; ?>		
    <?php endif ?>
    <label class="cbcontainer">
      <?php echo "<input type='checkbox' name=vote_list[] value='{$article['dance_name']}' $isChecked>" 
             . ' <b>' . $article['dance_name'] . '</b> by ' . $article['choreographer'] 
             . ' (' . $article['level'] . ')'; ?>
      <span class="cbcheckmark"></span>
    </label>
  </form>
<?php endforeach ?>

Thanks.


#2

Well, that didn’t go as planned. Can someone let me know how to post a block of code without it getting messed up?

Thanks.


#3

Posting code between bbcode [ code ] your code… [ /code ] tags (without the spaces inside the tags) works for me. You should be able to edit your code above (it’s all actually there) and add them.


#4

surround the php with a code block:

  [code] <?php echo "like so"; ?> [/code]