New Feature: Playlist Center! Pick a topic and let our playlists guide the way.

Start learning with our library of video tutorials taught by experts. Get started

Dreamweaver with PHP and MySQL
Illustration by

Working with multiple checkbox controls


From:

Dreamweaver with PHP and MySQL

with David Gassner

Video: Working with multiple checkbox controls

One of the most complex skills you need to learn to work with data entry forms is how to deal with multiple choice questions in a form that are represented by multiple check box controls. A single check box control is dealt with as a yes or no question. If the check box is selected, that means the user has selected the option, and if it's deselected, that means no. But with multiple check box selections to a single question, one very common way of dealing with it is to give all the check boxes the same name, and then to handle the results on the server using a little bit of PHP code.
Expand all | Collapse all
  1. 8m 48s
    1. Welcome
      1m 25s
    2. What you should know before watching this course
      2m 17s
    3. Using the exercise files
      1m 40s
    4. Understanding the differences between Dreamweaver CS5.5 and CS6
      3m 26s
  2. 19m 31s
    1. Understanding static vs. dynamic web pages
      4m 32s
    2. Selecting application and database servers
      6m 10s
    3. Introducing Apache, MySQL, and PHP
      6m 36s
    4. Installing Apache, MySQL, and PHP
      2m 13s
  3. 39m 34s
    1. Defining a Dreamweaver site
      3m 22s
    2. Configuring a PHP testing server
      7m 48s
    3. Creating and testing a PHP-based web page
      8m 25s
    4. Adding PHP commands with the Insert panel
      3m 14s
    5. Setting and outputting simple variables
      3m 56s
    6. Testing pages with Live view and Live Code view
      2m 9s
    7. Using server-side includes
      7m 50s
    8. Navigating included pages with the Code Navigator
      2m 50s
  4. 36m 37s
    1. Using code hinting with PHP variables
      5m 31s
    2. Understanding PHP custom classes
      6m 38s
    3. Adding Zend Framework to PHP on Windows
      5m 18s
    4. Adding Zend Framework to PHP on Mac
      4m 2s
    5. Using the Site-Specific Code Hints feature
      3m 43s
    6. Using Zend Framework classes with code hints
      7m 26s
    7. Managing reusable code with the Snippets panel
      3m 59s
  5. 18m 27s
    1. Understanding relational databases
      5m 26s
    2. Creating a MySQL database in phpMyAdmin
      4m 41s
    3. Adding data in phpMyAdmin
      2m 46s
    4. Importing a completed database from a script
      5m 34s
  6. 39m 35s
    1. Defining a Dreamweaver database connection
      5m 27s
    2. Building a simple recordset
      4m 31s
    3. Building an advanced recordset
      5m 1s
    4. Displaying data with repeating regions
      6m 4s
    5. Displaying data in a dynamic table
      4m 15s
    6. Formatting dynamic data
      4m 54s
    7. Displaying the total number of records
      2m 4s
    8. Limiting records with paging controls
      4m 5s
    9. Creating conditional regions
      3m 14s
  7. 43m 12s
    1. Building a simple data entry form
      5m 27s
    2. Handling form submissions with PHP
      5m 12s
    3. Creating a customer email form
      3m 9s
    4. Validating form controls with Spry
      7m 54s
    5. Populating a list control with dynamic data
      4m 50s
    6. Working with multiple checkbox controls
      8m 5s
    7. Sending email with Zend_Mail
      8m 35s
  8. 50m 51s
    1. Using data wizards
      6m 20s
    2. Formatting dates for SQL
      5m 27s
    3. Creating a custom data entry form
      4m 50s
    4. Preparing a database table for server behaviors
      3m 3s
    5. Using the Insert Record server behavior
      5m 42s
    6. Preparing an update form
      7m 6s
    7. Using the Update Form behavior
      5m 46s
    8. Creating list page links to edit and update data
      7m 3s
    9. Using the Delete Record server behavior
      5m 34s
  9. 14m 45s
    1. Creating a login form with a PHP server behavior
      6m 29s
    2. Protecting page access with PHP server behaviors
      4m 17s
    3. Logging out with a PHP server behavior
      3m 59s
  10. 22m 50s
    1. Configuring a remote server with FTP credentials
      4m 42s
    2. Synchronizing site assets with the remote server
      5m 27s
    3. Exporting the MySQL database to a script
      3m 8s
    4. Importing the MySQL database on a remote server
      2m 24s
    5. Configuring the site for the remote database
      7m 9s
  11. 52s
    1. Final thoughts
      52s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Dreamweaver with PHP and MySQL
4h 55m Intermediate Sep 22, 2010 Updated Jun 12, 2012

Viewers: in countries Watching now:

Join author David Gassner as he describes how to add dynamic data to a PHP-enabled web site in Adobe Dreamweaver. This intermediate course shows how to plan and create a MySQL database, define a PHP-enabled site in Dreamweaver, connect the site to the database, and manage and present dynamic data. David also explores Dreamweaver features such as PHP custom class introspection and site-specific code hinting as well as the differences between the CS5 and CS6 versions of the software.

This course was updated on 6/12/2012.

Topics include:
  • Understanding dynamic versus static content
  • Adding PHP commands to web pages
  • Setting and outputting variables
  • Using server-side includes
  • Creating PHP custom classes
  • Adding the Zend Framework to a PHP installation
  • Creating a MySQL database
  • Adding data in phpMyAdmin
  • Building recordsets
  • Formatting dynamic data
  • Building data entry forms
  • Authenticating users
  • Deploying a dynamic site
Subjects:
Developer Web Databases Web Development
Software:
Dreamweaver
Author:
David Gassner

Working with multiple checkbox controls

One of the most complex skills you need to learn to work with data entry forms is how to deal with multiple choice questions in a form that are represented by multiple check box controls. A single check box control is dealt with as a yes or no question. If the check box is selected, that means the user has selected the option, and if it's deselected, that means no. But with multiple check box selections to a single question, one very common way of dealing with it is to give all the check boxes the same name, and then to handle the results on the server using a little bit of PHP code.

I'll demonstrate how to do this with a version of my data entry form called join4.php, in the explorers folder. The first step is to make sure that all of your check boxes are named the same, and that they have a little bit of extra notation at the end of the name that turns them from a simple variable into something called an array. An array is an ordered collection of data. For example, this check box with a value of Backpack Cal has a name of interested, and if I look at the properties for the other check boxes in this set, you'll see they all have this same name.

In order to deal with them in PHP, change the name of the check box and add a beginning and ending bracket - that's the square bracket character, not the curly brace - and do the same thing for each of these check boxes. I'll click on each one in turn and type in the beginning and ending bracket, and then I'll be ready to do a little bit of hand coding in PHP. The actual processing of the PHP code is not something that Dreamweaver will help you with.

It's one of those circumstances where you just have to code it yourself. I have nine check boxes, they all have the same name, and they all have the beginning and ending brackets at the end of the name, indicating that they will be an array of values. Also notice that each of the check boxes has a unique, checked value. Let's take a look at how that is reflected in the actual HTML code. I'll go to Code View and show you that each of the check boxes is an input control. It has the name that I've assigned of interested with the array notation.

The type is check box. The ID is the same as the name right now, but that's something you might want to change later. Then the value for each of the check boxes is unique. Now when the user submits the form, we're going to be submitting the form back to itself. To make that happen, I've set the Action attribute using a PHP expression of _server PHP_self. That means the current page as it's seen by the browser.

So now go to the top of the code. Whenever you place code in a PHP page that already has a database connection include, place the custom PHP code after that. That will ensure that Dreamweaver can still find the connection for further work with databases. After the require_once command for the database connection, I'll create a new PHP code block. Then within the code block, the first question I'll ask is, has the form been submitted? The button in the form has a name of Submit, and that's going to create a new post variable named submit when the form is submitted.

So I'm going to use a PHP function called isset. I'll type the first few characters of the function, iss, and press Ctrl+Space, and there's my function, isset. Does the submit variable in the post-array exist? That code will look like this, $_POST, with post in all uppercase, then bracket, quote, submit, close quote, close bracket, close paren and close paren.

So, if this condition is true, that means the form has been submitted. I'll add a pair of curly braces where I can place code that I want it to execute only in that condition. Now, I'll ask the question, has the user checked any of the check boxes? Once again, I'll use the isset function. If the user checks at least one check box, there will be a post variable with the name of the check box, and it will be an array. If they haven't checked any of the check boxes, than that variable won't exist at all.

So, once again, I'll use an if command, and I'll call the isset function, and this time, I'll look for the variable 'interested.' Notice in this circumstance, I don't put in the opening and closing bracket. I only put that into the HTML code. When the user selects one or more items though, this variable will show up as an array. Once again, I'll add a pair of braces, and I'll also add an else section for the alternative state.

I need to make sure that I've added the extra parenthesis at the end of the line there, and that'll fix my syntax error. In the condition where the user has checked at least one of the check boxes, I'm going to transform the array - which is complex object - into a comma delimited string. For that, I'll use the PHP implode function. It looks like this. I'm going to create a variable called strInterested. It'll be a string values, so I'm prefixing it with str, and I'm going to get this value using the implode function, which looks like this.

You pass two values into implode. The first value, or argument, is called the glue. It's a character, or set of characters, that's going to separate the values in the array from each other. I'll type in ",". You can use either single or double quotes in this circumstance, and then I'll pass in, as the second argument, $_POST, bracket, quote, interested. This transforms the complex array into a string that has commas between the values in the array.

In the circumstance where the user hasn't selected any of the check boxes, I'll explicitly set strInterested to a blank string. So now, no matter what the user does with those check boxes, the strInterested variable will exist. I'm just going to add a little bit of debugging code. After the conditional clause, I'll use the echo command. I'll start with a literal string of "interested in," and then I'll append to that strInterested.

The dot is used to append one value to another. Then because I'm only debugging at this point - I'm not actually doing anything with the values - I'll call the PHP exit function, which terminates the processing of the current page and will simply output to the browser whatever I've echoed in this function. Now I'm ready to test my form. I'll save my changes and preview the page in an external browser, making sure that I copy the file over to my server directory. I have to fill in some minimal information in this form to satisfy its client-side validation rules, so I'll type into the first name Joey, last name will be Smith. The e-mail will be joey@abc.com.

I also need to fill in password information, because I have validation rules there. Then I'll go down to the Tool Profile section, and I'll select some random check boxes. I'll click the Join! button, and there's the result, a comma delimited list of the values that the user has selected. So that's how you prepare a form with multiple check boxes and then handle their selections on the server, using a little bit of custom PHP code.

This is an example of a circumstance where Dreamweaver can't actually generate the code for you, and so understanding how to create the code in PHP is an invaluable skill.

Find answers to the most frequently asked questions about Dreamweaver with PHP and MySQL.


Expand all | Collapse all
please wait ...
Q: The Bindings panel is disabled, and I can't create new queries or form variables in the current PHP file. How can I correct this problem?
A: This indicates that the file you have open isn't a part of your current site. For example, you might have opened a file from one site, then switched sites and tried to continue working on the same file. Try closing all files, then opening the file you want to work on from the Files panel. This ensures that the current file and site are in sync.
Q: I'm having trouble getting code hinting to work on Mac OS X. Are there know issues that could be causing the issues?
A: There might be an issue with your code hinting configuration. Make sure the folders you designated in the code hinting config screen match the disk location where you copied the Zend Framework files. You should have a file named dw_php_codehinting.config in your site root folder after setting up your code hinting configuration. Assuming you copied the Zend Framework files to a folder on your Mac named /phpincludes, the contents of the file might be: "/Volumes/Macintosh HD/phpincludes/ZendFramework/library/Zend/Date" EXTENSIONS(.php) "/Volumes/Macintosh HD/phpincludes/ZendFramework/library/Zend" EXTENSIONS(.php).  The exact path will differ depending on your hard disk name and the folder to which you copied Zend Framework. For subsequent exercises in the video series, the sample files provided with the course have the configuration for Windows as demonstrated in the videos. Once you get code hinting working in one exercise, you can copy the working dw_php_codehinting.config file from the current site folder into the new site folder.
Q: I’m following along in the video "Configuring a PHP testing server." When I go to preview the index.htm or .php files, I don't get the Dependent Files dialog box, and I get the page in my browser with just the HTML and no styling. The index file gets copied to the proper folder, but none of the dependent files are getting copied over. How can I resolve this issue?
A: If you are experiencing this problem, check your settings in Dreamweaver. The prompts for putting files onto the server have most likely been turned off. Follow these steps: 1) On Windows, select Edit > Preferences. 2) In the Preferences dialog, select the Site category. 3) Make sure your options for Dependent Files (prompt on get/check out, and prompt on put/check in) are selected. 4) Make sure your Put and Move options are selected (located at the bottom of the screen). 5) Then try previewing the file again. The dialogs should appear.
Q: I am having a problem with the "Handling form submission with PHP" video in Chapter 6. When I create a form variable "firstname" in the the Binding panel, in the Simpleform2.php file, I don't see the new variable in the list afterwards. It's as if the panel is disabled. What's going on?
A: Some users have reported that this problem can be corrected by deleting a file named  ".mno" from the site folder's _notes subfolder. The file is hidden, so you won't see it in Finder on Mac or Explorer on Windows. Note that there might be many files in the _notes subfolder with the .mno extension, but you only need to delete the file with no name and just the extension.

Follow these steps to delete the file:

Windows:
Open a command window
Switch to the site folder
Type these commands:

cd _notes
attrib -H .mno (this removes the hidden flag from the file)
del .mno (this deletes the file)

Mac OS X:
Open Terminal
Switch to the site folder
Type:
cd _notes
ls -a .mno (if the file is there, this command will show it)
rm .mno (this deletes the file)
Q: I want to use the Zend Framework in my PHP site, but my internet service provider (ISP) doesn't let me modify the php.ini file to include the files as taught in the course. What can I do?
A: If your host doesn't let you make changes to your php.ini file, you can include the Zend Framework with one of these strategies:

  • Copy the Zend Framework to the folder containing your web site files. In your PHP pages, your 'include' command can refer to the appropriate files with relative directory addressing:

 <?php include('../ZendFramework/library/Zend/Date.php'); ?

  •  If your shared host provides a special directory to contain your web files (for example, it might be named 'www' or 'web'), then you can add the Zend Framework files to your root folder as a sibling to the web folder. You'll need to find out the physical folder name; PHP's $_SERVER['DOCUMENT_ROOT'] variable can help you find this:

 <?php echo $_SERVER['DOCUMENT_ROOT']; ?

You can then programmatically modify the include_path variable at runtime with the set_include_path() function. For example, if your physical root folder is /home/myroot, the code might look like this:

<?php
set_include_path('.' . PATH_SEPARATOR .
'/home/myroot/ZendFramework/library/Zend');
include('Date.php');
?
Q: This course was updated on 6/12/2012. What changed?
A: This course was updated to show the minor UI differences between Dreamweaver CS5 and CS6, especially the change from separate Live Code/Live View buttons to a single Live button.
Q: phpMyAdmin is not opening properly in the second lesson in Chapter 4, "Creating a MySQL database in phpMyAdmin." The error message says:

#2002 - The server is not responding (or the local MySQL server's socket is
 not correctly configured)
A: The error indicates that there's an incorrect reference to the MySQL 'sockets' file. This is set automatically during WampServer installation, but if you've previously installed other copies of MySQL there can be some leftover conflicts (even if you've uninstalled the other copies).

Check your system for duplicate copies of the file 'my.ini' - it's a MySQL configuration file that might have been left around from a previous installation. The most likely folder in which to look is c:\windows\System32, but it could also be elsewhere. If you find any such files that aren't in the c:\wamp directory structure, rename or delete them, then reboot your system.

If that isn't the issue, you'll need to start from scratch: back up your working files from c:\wamp\www, then uninstall WampServer, delete the c:\wamp folder completely, and reboot and reinstall. Test phpMyAdmin immediately after installation. Then, if it stops working along the way you'll have better information about what steps might have cause the issue.
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Dreamweaver with PHP and MySQL.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Notes cannot be added for locked videos.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.