navigate site menu

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

Dreamweaver with PHP and MySQL
John Hersey

Dreamweaver with PHP and MySQL

with David Gassner

 


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

show more

author
David Gassner
subject
Developer, Web, Databases, Web Development
software
Dreamweaver CS5, CS5.5, CS6
level
Intermediate
duration
4h 55m
released
Sep 22, 2010
updated
Jun 12, 2012

Share this course

Ready to join? get started


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Welcome
00:04Hi! My name is David Gassner and I'd like to welcome you to Dreamweaver CS5 with PHP and MySQL.
00:12For many web site developers who have learned how to build simple web sites with
00:16HTML and CSS, the next step is to add dynamic capabilities with application
00:22servers and databases.
00:24Dreamweaver CS5 offers powerful support for integrating one of the most popular
00:28combinations of such software, PHP and MySQL.
00:33In this video series, I'll show you how to use Dreamweaver CS5's new PHP code
00:39hinting capabilities.
00:41Then I'll describe how to generate PHP code that connects to MySQL, retrieves
00:47and displays data from the server, and inserts, updates, and deletes data based on
00:52information provided by a web site visitor,
00:55and show you how to authenticate your site visitors and provide access to your
00:59web pages on an as needed basis.
01:03This video series is designed for developers who are already comfortable with
01:06the basic building blocks of all web sites.
01:10I hope it will help you jumpstart your knowledge and use of advanced tools, the
01:15PHP application server, and language and the MySQL database, and help you quickly
01:20create the code you need to integrate these tools into your own web sites.
Collapse this transcript
What you should know before watching this course
00:00Before we get started with this video series, I'd like to talk a little bit
00:04about how the course is designed and who it's designed for.
00:08Dreamweaver is primarily a design environment. It helps you build visually
00:12compelling web sites and integrate HTML and cascading style sheets together,
00:18but in addition, Dreamweaver can help you work with dynamic application servers,
00:23including Adobe's own ColdFusion, Microsoft's Active Server Pages, or ASP, and PHP
00:31the open-source application server that this course focuses on.
00:35The course is designed for developers who already have some background with
00:38Dreamweaver and want to incorporate PHP and MySQL to develop data-driven web sites.
00:46For developers who are new to SQL and PHP, Dreamweaver can help you minimize the
00:51amount of required hand-coding and for those who do know PHP;
00:56Dreamweaver will help you with code hinting and syntax-checking capabilities.
01:01Before working through this course, you should already know how to create a
01:05simple web site in Dreamweaver that uses static HTML pages.
01:10You should have a background with cascading style sheets, or CSS, that's used to
01:14define the appearance of a web page.
01:17You do not need to know how to code in PHP or SQL.
01:22All of the server-side code used in this course is either generated by
01:26Dreamweaver or is hand-coded with plenty of explanation of how it works.
01:31Before you take this course, if you're new to Dreamweaver, I recommend watching
01:36the appropriate introductory video series;
01:39Dreamweaver CS5 or Dreamweaver CS6 Essential Training, which you can find in the
01:44lynda.com online training library, and after you watch this course, if you're
01:49interested in learning more about PHP and MySQL, lynda.com has plenty of content
01:55on these subjects, including PHP with MySQL Essential Training, PHP with MySQL
02:02Beyond the Basics, and MySQL Essential Training.
02:06These courses will help you take your server-side coding skills to the next level.
02:11Now let's move onto the course, Dreamweaver with PHP and MySQL.
Collapse this transcript
Using the exercise files
00:00Just a quick word about the exercise files I'll be using.
00:03If you're a premium member of the lynda.com online training library, or if you're
00:08watching this tutorial on a disk, you have access to the exercise files used
00:12throughout this title.
00:14In the Exercise Files folder I've collected some assets for you to use during
00:19our tour of building dynamic web sites with Dreamweaver and PHP.
00:23They include graphic files, an SQL script to create a sample database, and
00:30starting web page files for use in the sample web sites that I'll be creating.
00:34I've copied the folder to my Desktop, but you can put it wherever you want.
00:38To get started with the video series, you'll need to follow the instructions in
00:41Chapter 1, where I describe how to install the server software you'll need;
00:46WAMP Server for Windows or MAMP for Mac OS X.
00:50From that point forward, you can choose to work through the entire video series
00:54from start to finish, or if you'd like to jump in at a particular chapter, you
00:59can use the starter files for that chapter.
01:02In some chapters, such as Chapter 2, I have an entire new version of a site for each exercise.
01:07In other chapters, such as those working with databases, I've created a single
01:12copy of the web site that you'll use throughout the chapter.
01:15For these chapters especially, I recommend always watching the first video of
01:20the chapter, since I frequently give instructions for configuring the new
01:23version of this site before launching into the chapter's individual exercises.
01:28If you don't have access to the exercise files, you can still follow along the
01:33instructions and demonstrations on screen and use any files you want as you
01:37create your own dynamic web site.
Collapse this transcript
Understanding the differences between Dreamweaver CS5.5 and CS6
00:00This video is intended for users of Dreamweaver CS6.
00:04If you're using Dreamweaver CS5 or Dreamweaver CS5.5, you can skip this video
00:09and go on to the rest of the course.
00:12This video series was originally recorded in Dreamweaver CS5, but everything I
00:17teach in the series can be done with all three versions of Dreamweaver it
00:20targets, CS5, CS5.5 and Dreamweaver CS6.
00:26However, Dreamweaver CS6 introduced a couple of minor user interface changes
00:31rearrangements and re-labeling of buttons that I'm going to talk about here.
00:36I'm looking at Dreamweaver CS5.
00:38Notice in Dreamweaver CS5, there is a button called Live Code and another
00:42one called Live View.
00:44The intent in Dreamweaver CS5 was that you should first click the Live View
00:49button to trigger a deployment tier testing server and then a display of
00:54the finished web site.
00:56You could also then click the Live Code button and you'd see the generated code
01:01coming from the PHP page.
01:03To get out of this state, you would click Live Code again, and Live View.
01:09In Dreamweaver CS6, the Live View and Live Code buttons have been replaced by a
01:14single button labeled Live.
01:17When you click the Live button in Dreamweaver CS6, it's just like clicking Live
01:22View in CS5 and 5.5. Just like those versions, you might be prompted to Update
01:28the copy of your code on the testing server and to copy dependent files over,
01:33but then you will see the resulting web site displayed.
01:37The Live Code button is still there, but in CS6 it only appears when you're
01:41already in Live View, and you'll see it here, and just like in CS5, it results in
01:47showing the generated code from the PHP page.
01:51Here is another minor user interface difference from CS5 to CS6.
01:56To create a brand new site, you can go to the Menu and choose Site > Manage Sites.
02:02In the Manage Sites dialog in Dreamweaver CS5, you then click a button named New,
02:08and you'll see the buttons stacked from top to bottom.
02:11When you click the New button that takes you into the Site Setup dialog.
02:16In Dreamweaver CS6, to get to the Site Setup dialog, you use the same exact menu
02:21sequence, choose Site > Manage Sites, and you'll see that the Manage Sites
02:27dialog has been redesigned.
02:29Instead of a set of buttons that were stacked vertically, you'll see descriptive
02:33buttons laid out horizontally at the bottom of the dialog box and some
02:37operations are now assigned to icons, the minus icon for deleting a site
02:42definition, the pencil for editing, and so on.
02:45In this video series, I'll describe how to create a new site.
02:50In CS5, you click the button labeled New, but in CS6 you click New Site.
02:56The functionality however is exactly the same, and that's pretty much it for
03:01differences in user interface from CS5 to CS6, at least in regards to this video series.
03:08All of the other functionality that I described, such as connecting to
03:12databases, creating bindings, using server behaviors and using the Files, Assets
03:19and Snippets panels, work exactly the same and look the same as in the older
03:24version of the software.
Collapse this transcript
1. Understanding Browsers, Servers, and Databases
Understanding static vs. dynamic web pages
00:00Whenever you incorporate a dynamic application server into a web site, it's
00:05important to understand how the process works.
00:08First, let's talk about how static web sites operate.
00:12A static web site is a collection of web pages, Cascading Style Sheet files,
00:17image files, and other related assets.
00:21All of these assets are stored on a server and then delivered to web clients such
00:25as browsers, using a kind of software called an HTTP server.
00:30There are number of popular HTTP servers on the market, but the two most common
00:35are Internet Information Services, or IIS, a free web server that's included
00:41with the Windows Operating System, and Apache,
00:44a free open source HTTP server product which is used on pretty much all
00:49operating systems, including Windows, Linux, Mac OS X, and other flavors of UNIX.
00:57With static web sites, a client, such as a web browser stored on a personal
01:02computer or a mobile device, sends an HTTP request.
01:08HTTP stands for Hypertext Transfer Protocol.
01:11The format of the request is in a URL, which stands for Uniform Resource Locator.
01:18A URL could be http://www.lynda.com.
01:24That would mean that the request is going to the default directory on
01:28lynda.com's web site.
01:30The server receives this request and then figures out what it means.
01:35The request typically points to a particular file on the server's disk.
01:39The server retrieves the file, opens it up, gets its content, and sends that
01:45content back to the client as an HTTP response.
01:48Here is a little diagram that shows how it works.
01:52The client sends the request to the server.
01:56The request is in the form of the URL.
01:59The server finds the file and sends its content back to the client.
02:04So that's a static web site.
02:07When you mix in an application server, your web site becomes dynamic.
02:12The application server software, such as PHP, ColdFusion, or ASP, is installed on
02:18the same physical computer, typically, as the HTTP server software.
02:23The client, that is the web browser, once again sends an HTTP request,
02:28formatted as a URL.
02:31The client doesn't know that there is an application server involved.
02:35The request looks exactly the same to the web browser, regardless of whether the
02:39web site is dynamic or static.
02:42The HTTP server software receives this request, but instead of responding to
02:47it directly, as it does with a static web site, it dispatches the request to
02:51the application server.
02:53It knows how to do this by looking at the file extension in the URL.
02:57If the file extension is .cfm,
03:00that's a request for the ColdFusion Server. .asp would be for Active Server
03:05Pages, .aspx for ASP.NET and .php for the PHP application server.
03:13The Application Server works with server-side resources, such as databases, XML
03:19files. and other content, and then dynamically constructs an HTTP response. which
03:24is sent back to the client.
03:26Once again, here is a diagram that shows how it works.
03:30The client sends the request to the server, formatted as a URL,
03:35the HTTP server receives the request, and now dispatches it to the
03:39Application Server,
03:41the Application Server might work with the database on the server to get some content.
03:46The data is returned to the Application Server.
03:49The Application Server constructs an HTTP response, returns that to the HTTP server;
03:56and the HTTP server returns the content to the client.
04:00Once again, the important thing here is that the client doesn't know an
04:03application server is involved;
04:05its relationship is directly to the HTTP server.
04:09So that's how dynamic web sites differ from static web sites.
04:13Once you involve an application server, such as PHP, your HTTP response,
04:18typically in the form of HTML, or Hypertext Markup Language, is constructed
04:23dynamically by the application server, instead of stored statically in a
04:28document on the HTTP server's hard disk.
Collapse this transcript
Selecting application and database servers
00:00In this video series, I'm going to describe using Dreamweaver CS5 with PHP and
00:05MySQL, but if you're new to the world of web application development, you might
00:10be wondering about what other server software is available.
00:13When you choose software for your server, the choice is driven by a number of factors.
00:19Probably the single most important factor is your existing experience and
00:23expertise, either yours personally, or your organization's.
00:27If an organization, for example, already uses ASP.NET everywhere else, they're
00:32unlikely to choose a new application server just because it has a particular
00:36feature that might be interesting.
00:38Another factor is the operating system of the server itself.
00:42ASP.NET and ASP for Microsoft only work on Windows.
00:46Other application servers work on many operating systems.
00:50You might also be influenced by the available programming languages supported by
00:54a particular server.
00:56And finally, there is cost.
00:58Certain server software is free, and other packages require license fees.
01:03There are three elements of the server stack to choose:
01:07the HTTP server, which receives request and sends responses with the client or a
01:12web browser, the application server where you do most of your server
01:16programming, and the database server.
01:18Here are the available choices for an HTTP server.
01:22There are many HTTP server products on the market, but there are two primary
01:27products that dominate the landscape.
01:30On the Windows platform, you have Internet Information Services, also known as IIS.
01:35This is a Microsoft product that's included with all copies of Windows
01:40server-based operating systems.
01:43And then the other major choice is Apache.
01:45Apache is completely free and open source, and it works with all major operating
01:50systems, including Windows, Linux, Mac OS X, and many others.
01:56You can download Apache for free from http://www.apache.org.
02:03You don't need to register or otherwise report the usage of this software.
02:09You can also get Apache in many bundle distributions that include Apache, PHP, and MySQL.
02:15I'll describe these in a separate video.
02:20When choosing an application server, if you already know you'll be working on
02:24the Windows platform, you can look at either Active Server Pages, or ASP, or the
02:29more recent ASP.NET.
02:32These products only work on the Windows platform, although particularly with
02:37ASP.NET, there is a distribution that's built by a third party called Mono
02:41that works on Linux.
02:42If you're working in Active Server Pages, you'll be working with the languages
02:46VBScript or JScript, and if you're working with ASP.NET, you'll most likely be
02:51working with either C# or VB.NET.
02:55ASP and ASP.NET are included with all copies of the Windows
03:00server-based operating systems.
03:02Technically, they aren't free, because you have to pay for Windows, but
03:06they're both lower cost than other application servers that you have to pay a
03:10separate license fee for.
03:12You can also choose Java-based servers, known as Java EE or Java
03:16Enterprise Edition.
03:18These were formerly known as J2EE.
03:21Examples of Java Enterprise Edition Servers include JBoss, Tomcat, WebLogic,
03:27GlassFish, and Geronimo.
03:30All of these servers work on multiple operating systems, including Windows, Mac,
03:34and Linux, and they all require knowledge of, and use of the Java programming
03:39language, which is distinct from JavaScript, the language you use in the browser.
03:44Some of these products are free, such as JBoss, Tomcat, and GlassFish, and others
03:50require license fees, such as WebLogic.
03:54There is also Adobe ColdFusion, which works on multiple operating systems, and
03:58works with all of the popular HTTP servers, such as Apache and IIS.
04:03When you work in ColdFusion, you'll be using its proprietary language,
04:07ColdFusion Markup Language, or CFML, a tag-based language.
04:12Adobe ColdFusion requires a separate license fee, and it's available from Adobe systems.
04:18And finally, there is PHP.
04:20PHP works on multiple operating systems, just like ColdFusion.
04:24It has its own programming language, also called PHP.
04:28It's commonly paired with the MySQL database server, and it's completely
04:33free and open source.
04:34In this video series, I'll be working with PHP exclusively, although Dreamweaver
04:39CS5 does have very strong support for Adobe ColdFusion.
04:44Finally, there is the database server.
04:46One of the most popular database servers out there is Microsoft SQL Server.
04:51It operates only on the Windows platform, and the enterprise edition
04:56requires license fees.
04:58There is a community edition of Microsoft SQL Server that has
05:01limited capabilities.
05:03There is also Oracle, sometimes known as the 800-pound gorilla of the database world.
05:08Oracle works on multiple operating systems, including Windows and Linux, and
05:13there are license fees involved in using it.
05:16It's also very complex to set up and maintain.
05:19So, if you're planning a small-scale web site, you probably won't be interested
05:23in this database platform.
05:26Finally, there is MySQL, also known as my sequel.
05:31The community edition of MySQL is free.
05:34You can download it from www.mysql.com.
05:38You also see MySQL frequently included in web site plans from Internet service providers.
05:44If you rent a shared web site at one of these ISPs, you'll typically see both
05:49PHP and MySQL support included.
05:51MySQL, once again, is frequently used with PHP, and it's included in many server
05:58bundle distributions that include both PHP and Apache, and I'll talk a lot more
06:03about these server bundles and about the entire concept of multi-tier
06:07applications in a separate video.
Collapse this transcript
Introducing Apache, MySQL, and PHP
00:00In a previous video, I described the available server software that you can
00:04choose from, and I specifically talked about Apache, PHP, and MySQL, the three
00:11elements that together are known as the AMP technology.
00:15I'd like to talk a little bit here about the nature of multi-tier applications,
00:19which is how we describe the architecture used in web-based applications.
00:24Multi-tier means that there are multiple elements that go into building a
00:28web-based application.
00:30The client tier is the first tier.
00:33It's the one that the user interacts with directly, and it typically consists of
00:37a web browser hosted on a personal computer or other Internet connected device.
00:43On the server, there are three major tiers:
00:46the web tier, or Gateway, which receives request from the client, typically
00:50implemented as an HTTP server; the business tier, which contains the business
00:55logic on the server, typically implemented in an application server; and the
01:00data tier, typically implemented in a database server, such as MySQL, SQL Server or Oracle.
01:08The client tier is the web browser, and its associated technologies.
01:12The web browser itself sends requests, receives responses, and renders HTML, or
01:19Hyper Text Markup Language, images, Cascading Style Sheets and other content
01:24that it's capable of rendering directly.
01:27It also hosts plug-in components.
01:30So it can execute both native client- side code in the form of JavaScript and
01:35also embedded code that's executed by the plug-ins.
01:38For example, Flash Player is used to render Flash content that uses ActionScript code.
01:44All of this taken together is known as the client tier.
01:48The server part of a multi-tier application is implemented with multiple
01:52software packages that are designed to work together using web standards.
01:57The first tier is known as the web tier, or The HTTP server, and once again, it
02:01receives the request from the client and returns the response.
02:05Many of these responses are text- based, including HTML, Hyper Text Markup
02:10Language, and XML, Extensible Markup Language.
02:14Other content returned by the HTTP server would include binary files, such as
02:19images and Flash SWF files.
02:23The business tier is the application server and once again the data tier is
02:27the database server.
02:28In a server environment that uses AMP technologies, the web server is Apache,
02:35the application server is PHP, and the database server is MySQL.
02:41If you choose, you can download native versions of the server software packages.
02:46The three packages together are known as the AMP technology stack.
02:51You'll typically see them called WAMP, if they're hosted on Windows, LAMP on
02:55Linux, and MAMP on Mac OS X. If you want to download and install each element
03:01of the server stack individually, you can go to the web sites that host these packages.
03:07You'll find the Apache software at www.apache.org, PHP at php.net, and MySQL at mysql.com.
03:18If you download these individual software packages, it's up to you to configure
03:23them to work together.
03:25Depending on which operating system you're working on and which installer you
03:28download, you'll get a certain amount of help in configuring them to work
03:32together. But if you want to get launched very quickly, you can instead choose
03:37to use a server bundle.
03:39A server bundle allows you to get started very quickly with almost no configuration.
03:45All of the server bundles I'm going to recommend here are free to download
03:48and use, and once you download, you can install them and get started using
03:53them almost instantly.
03:55If you're working on Windows, I recommend WampServer, which you'll find at
03:59www.wampserver.com/en.
04:03This is the server bundle that I'll be using in all of the demonstrations
04:06in this video series.
04:08I typically do my web development on the Windows platform, and this is my
04:12favorite server bundle for Windows, because it's so easy to install and so
04:17tough to get wrong.
04:18If I'm working on Mac OS X, I typically choose MAMP, which you'll find at
04:23www.mamp.info/en, and I'll give you complete instructions in this video series
04:30about how to install MAMP, and how to use it during the video series.
04:35Even though most of my demonstrations will be shown on Windows with WAMP server,
04:39I'll mention how you should adapt those instructions if you're using MAMP.
04:44There are other options though, that I won't be using in this video series, but
04:48are worth checking out.
04:49There are two packages in particular that are designated from multiple operating systems.
04:55The first is called Xampp, X-a-m-p-p.
04:59You'll find this at www.apachefriends.org/en/xampp.html.
05:08There are versions of the Xampp server for both Mac OS X and for Windows.
05:13They're named the same, but they actually have different sets of software in them.
05:18They both include Apache, PHP, and MySQL, but they have different options and
05:23different user interfaces for managing them.
05:25And finally, there is the Zend Server Community Edition, available at
05:30www.zend.com/en/products/server-ce.
05:39The Zend Server Community Edition is probably the most complete of these server bundles.
05:43In addition to Apache, PHP, and MySQL, it also contains the complete Zend
05:50framework, a set of open source PHP- based tools that can simplify your use of
05:56the PHP application server.
05:59I'm not using the Zend Server Community Edition package in this video series,
06:03only because it's a little bit more complex to set up, particularly on Mac OS X,
06:08but if you get serious about doing PHP development, particularly if you learn
06:13how to hand-code PHP and get into more complex application options, I find that
06:19the Zend server package is the most powerful of any of these options.
06:24To summarize though, I'll be using WampServer on Windows for these
06:28demonstrations, and I'll be mentioning along the way how to adapt my
06:31instructions if you're using MAMP on Mac OS X.
Collapse this transcript
Installing Apache, MySQL, and PHP
00:00To follow along with the exercises in this video series, you'll need to install
00:04a local copy of the Apache HTTP server, the MySQL database, and PHP.
00:11There is a video course that teaches how to install these products locally that I created.
00:16It's named Installing Apache, MySQL, and PHP, and it's available completely free
00:22in the lynda.com online training library.
00:25In this course, there is an introductory chapter including a video about
00:29understanding Apache, MySQL and PHP and how they can work together.
00:34But then there are separate chapters on each of the different ways to
00:37install these products.
00:38There is a chapter on installing separate components on Windows, and one on
00:43separate components for Mac OS X, but if you're watching the video series about
00:47Dreamweaver with PHP and MySQL and want to match what I'm showing on my screen,
00:54if you're a Windows user, I recommend installing WAMP server, and if you're a Mac
00:58user I recommend installing MAMP.
01:01You should only have to watch and follow along with one of these two chapters.
01:06Don't install both separate components and one of these software bundles at the
01:10same time, because you might introduce port or DLO conflicts into your system
01:16and have a hard time getting things started, but if you follow along in these
01:20chapters, you should be able to get started very quickly.
01:24And if you have any trouble getting these software products installed and set up,
01:28you can also watch the chapter at the end labeled troubleshooting.
01:32I periodically update this course on installing these products, as things
01:37change in the real world.
01:38For example, there's a new version of PHP as of the time of this recording, PHP
01:445.4, and I'll be doing an update to this course to describe how to get started
01:49with that version if you want to use it.
01:52So watch this course to get started installing the software products and then
01:56once you have them installed and tested, come back to the course, Dreamweaver
02:00with PHP and MySQL, and continue through those exercises to learn how to work
02:06with PHP and MySQL from within Dreamweaver CS5, 5.5 or CS6.
Collapse this transcript
2. Getting Started with Dreamweaver and PHP
Defining a Dreamweaver site
00:00To get started building a web site that's associated with PHP, you define
00:05a Dreamweaver site.
00:07The first part of the process is the same, regardless of whether your site is
00:11static or dynamic within application server.
00:14In Dreamweaver CS5, I'll go to the Menu and select Site > New Site.
00:20You can also get to this Site Setup dialog by going through the Menu and
00:23selecting Site > Manage Sites and then clicking the New button.
00:29In the Site Setup dialog, you'll set the site name and the local site folder,
00:34I'm going to name my site DW CS5 with PHP and MySQL. You can name the site
00:42anything you want and you can include spaces in the name.
00:46Then set the local site folder to the physical location of the site root,
00:51I'll click the browse icon and I'll start at the Exercise Files folder, which
00:58I'll find on my Desktop.
01:00From there, I'll go down to 02_ gettingstarted to 01_definesite, where I have a
01:07complete set of site files, and I'll click Select.
01:11For a static site that's all you have to do.
01:14Now let's take a look at other elements of the Site Setup dialog in Dreamweaver CS5.
01:20The Servers category lets you setup your remote and testing servers.
01:24The testing server is the server that you work with on your local computer.
01:28The remote server is the production server where you host the web site
01:33for external users.
01:35I'll describe how to use this part of the site setup dialog in a separate video.
01:40The Version Control category lets you connect to a subversion repository, so you
01:45can manage your site files, checking them in, checking them out, and rolling back
01:50to previous versions.
01:52In the Advanced Settings folder you'll find settings for Local Info, Cloaking,
01:58Design Notes, and so on.
02:00These settings aren't specific to the world of PHP or application servers, so I
02:04won't be describing them in detail in this video series.
02:07I'll click Save and that creates the new site, and then if I started from the
02:12Manage Sites dialog, I need to click Done.
02:16In the Files panel I should now see a complete listing of the site's assets.
02:20HTML, image, CSS files, and so on.
02:24I'll click Expand button and that will show me a larger view of the files
02:29that are available.
02:30I'm working with my local file set.
02:33Here is the homepage of the existing site, index.htm;
02:38I'll double-click it to open it.
02:40Then I can test the page either through the Live View button, which opens the
02:44file directly from the hard disk, or if I prefer, I can deselect Live View and
02:50then go to the Preview button and select a particular browser, such as Firefox.
02:56Regardless of whether I use Live View or an external browser,
03:00notice that I'm testing the files by loading them directly from the hard disk.
03:05For a PHP-based site though, there's a little bit more work to do, setting
03:10up the testing server, and then testing the PHP pages by calling them from
03:15DHTTP server, rather than the hard disk, and I'll describe how to set that
03:19up in another video.
Collapse this transcript
Configuring a PHP testing server
00:00When you create a Dreamweaver site that's designed to work with PHP, there are
00:05some additional steps you'll need to follow to associate the site with your PHP
00:09server on your local system.
00:11I'll start with the site that's already been created named, DW CS5 with PHP and MySQL.
00:17I'll go to the Menu and choose Site > Manage Sites.
00:22Then with my site definition selected I will click Edit.
00:25Before I can figure the testing servers, I will reset the Local Site Folder for
00:30this site definition to another copy of the site files.
00:33I will click the Browse icon, then I will go up one level in the disk file
00:39system to the 02_gettingstarted chapter folder and then go down to the exercise
00:44folder, 02_testingserver, and then I will click Select.
00:49I will click Save, and if see this message that the cache will be recreated, I
00:54will click OK and then click Done.
00:59That's a process you will need to follow on each exercise, re-pointing the site
01:04definition to the files for that exercise, and then looking at the Files panel, I
01:10will confirm that I have a full set of files in that directory.
01:13Here are the steps for setting up the testing server.
01:17I'll return to Manage Sites dialog and with the site definition selected, I will click Edit.
01:23I will go to the Servers category.
01:26In the Servers list, I will click the plus icon to add a new server.
01:30I am going to be working with my copy of PHP and Apache on my local system.
01:37So I am going to name the server simply, Local Server.
01:41You can name the server anything you want at this point.
01:44For this option, Connect using, I will choose Local/Network, meaning that I'll be
01:50connecting to the Server's hard disk through the local file system.
01:53I'm going to set up a Server Folder which will be under my server document root.
01:59On Windows with WAMP server, this will be C:\wamp\www, and on Mac using MAMP, it
02:08will be /Applications/MAMP/htdocs.
02:13I am working on Windows with WAMP server, so I will click the Browse icon;
02:18I will start off at the computer in the C drive root.
02:23From there I will go down to wamp and then to www.
02:27If you are working on Mac, browse to /Applications/MAMP/htdocs.
02:34Create a new folder;
02:36this will be the testing folder for the current site.
02:39I'm going to name it dwwithphp.
02:42The name of this folder should contain no spaces and should be all lowercase.
02:47I'll click Open and then click Select, and that sets the Server folder to the
02:52location on disk where I'm going to copy my files for testing.
02:57Then click into the Web URL.
02:59The web URL will be the same regardless of whether you're working with
03:02WAMP server or MAMP.
03:04It'll be http://localhost/dwwithphp.
03:11You are matching the name of the folder in the web URL to the name of the
03:15folder in the server.
03:17Local host points to the server's document route and the rest of the directory
03:22name is relative to that location.
03:24Next click Advanced at the top of the screen.
03:28Don't worry about the Remote Server settings.
03:30We are setting up a testing server.
03:32So under Testing Server, pull down the list of available server models
03:37and choose PHP MySQL.
03:41Click Save, that takes you back to the server list.
03:45With your new server selected, uncheck Remote and check Testing.
03:50This means that the server will only be used for testing and we won't be
03:55actively uploading files for production.
03:57Later on if you need to make changes to this server definition, you can reopen
04:01this dialog box and click the Edit button in the form of a pencil.
04:07I'll Save all of my changes and then click OK, and then in the Manage Sites
04:12dialog, I will click Done.
04:15I'll show you what happens when you test a page from a PHP associated site.
04:19I'll open the file index.htm and then I'll test in an external browser.
04:25I will go to the Preview/Debug button in the toolbar and choose Preview in Firefox.
04:33Notice that I am asked whether I want to update the file on the testing server.
04:37You may or may not see this dialog depending on how you have
04:40Dreamweaver configured.
04:42If you do see it, click on Yes, and then in the Dependent Files dialog, click on Yes again.
04:48If you don't see these dialog boxes, asking you whether you want to copy files
04:52to the testing server, you can turn them on in Dreamweaver's Preferences dialog box.
04:59Once you open the Preferences dialog, go to the Site category and check the
05:04option, prompt input/check in.
05:08Click OK to save your changes and preview the page in an external browser again.
05:13You should see the dialog boxes appear.
05:16When the page opens in the browser, if you don't see any graphics, click the browsers
05:21Refresh button to make sure you're seeing the latest version.
05:25That means that before you test the page, Dreamweaver will make a copy of the
05:30page in your web directory along with any files on which it depends, graphics,
05:36cascading style sheets, XML, Flash content, and so on.
05:41In the external browser, take a look at the web address that's been used to test the page.
05:46Notice that you're browsing the page by requesting it from the web server,
05:50through the local host address, not loading the file from the local disk.
05:56This will enable the web server to dispatch requests for dynamic pages, such as
06:00PHP pages, to the appropriate application server for processing.
06:06Now I'll close the browser and return to Dreamweaver and close this page.
06:11Now let's see what happens with a PHP page.
06:13I will go to the Files panel to the index.htm file which is the homepage.
06:19Then I will rename it, I will right- click on it and choose Edit > Rename, and I
06:27will change the name of the file from index.htm to index.php.
06:32When I press Enter or Return, Dreamweaver detects all of the references to
06:37this page in any of the other pages of the site and asks me whether I want to update the links.
06:43I will click Update and Dreamweaver accomplishes the update throughout the site,
06:49and then I'll double quick index.php and I'll run the page in the browser.
06:56Once again I'm asked whether I want to update the copy on the testing server and
07:00in the secondary dialog, whether I want to put the dependent files.
07:03I will click Yes for both dialogs, and now I should say that the browser is
07:10loading the PHP version.
07:12So if you've gotten this far, you're successfully testing your PHP file by
07:17requesting it from the web server, which dispatches the request to the PHP
07:22server, which processes the file and sends content back to the client, the
07:27browser, through the HTTP server.
07:30If you're having trouble with this, make sure that your server is running, either
07:34WAMP server or MAMP, and also make sure that you can load HTML files correctly
07:40using the localhost web address.
07:42If everything is working, you're ready to start creating your own PHP pages.
Collapse this transcript
Creating and testing a PHP-based web page
00:00Once you've defined your Dreamweaver site and associated it with your PHP
00:04server, you can start creating brand new PHP pages.
00:08For the remainder of this video series, I'll work with Dreamweaver in a new
00:12workspace named App DeveloperPlus. You can get to this work space by opening the
00:17workspace selector on the top toolbar of Dreamweaver and choosing App
00:22DeveloperPlus. You should see the following layout:
00:25CSS Styles and AP Elements at the top, Files, Assets and Snippets at the bottom
00:31on the left, and then miniature buttons that allow you to open panels like
00:35Insert, Databases, Bindings and Server Behaviors.
00:41For this demonstration, I'll point my site definition to a new folder, I'll go to
00:47the Menu and choose Site > Manage Sites and then click Edit with the selected
00:52site, then for the local site folder I'll click the icon to browse.
00:57If you worked through the previous video, your folder will be pointed
01:00to 02_testingserver.
01:02I'll go up one folder from there and then down to 03_newphppage.
01:09I'll click Select and Save, and then click OK to close the cache notification
01:14dialog and click Done.
01:18The Files panel in this workspace appears in the lower left corner.
01:22You should see all of the site files and the PHP-based homepage, index.php.
01:29Now the goal of this demonstration is to create a brand new PHP page from scratch.
01:34From the Menu choose File > New.
01:38In the New Document dialog choose Blank Page category and then down at
01:42the bottom choose PHP.
01:45If you're creating a page for your own site, you might want to use one of the
01:49standard layouts provided in Dreamweaver CS5.
01:52These layouts make very good use of cascading style sheets, or CSS, to
01:57accomplish their layouts.
01:59You can choose any of these and your file will be created as a PHP file.
02:04I'm not going to use any particular layout though, because I want to keep this
02:07exercise very simple and focused. So I'll set the layout to None and click
02:12Create, then I'll go into Code view.
02:14As I've mentioned previously, a PHP page is nothing more than an HTML page.
02:21When you create a brand new PHP page from scratch in Dreamweaver, you end up
02:26with a skeleton of an HTML page.
02:28I'm going to set the title of this page, changing it from Untitled Documents to
02:33PHP Info, then I'll save the file, selecting File > Save As,
02:40and I'll name it phpinfo.php, because I designated this as a PHP file from the beginning.
02:47If I didn't add the file extension at this point, Dreamweaver would add .php for
02:52me, I'll click Save.
02:56Now I'm going to use a very simple PHP command that outputs information about
03:01the configuration and version number of my PHP server.
03:05I'll place the cursor after the starting body tag and press Enter a few times,
03:10and place the cursor between the body tags.
03:13then I'll go to the Insert panel, I'll click the Insert button, and in the panel
03:19I'll pull down the list of available options and choose PHP.
03:24The Insert panel will help you insert standard PHP code.
03:28I'm going to add a Code Block by clicking once, make sure you only click once,
03:34if you double-click, you'll get two copies of the code.
03:37Then I'll click back on the page and the Insert panel will shrink back down
03:42into its original place.
03:44A PHP Code Block looks like this, its starts with a less than character and a
03:48question mark and then the phrase php in lowercase, and it ends with a question
03:53mark and a greater than character.
03:55Within the PHP code block, you can add your own PHP code. I'm going
04:01to add a function called PHP info. I'll type php and then using Dreamweaver
04:07CS5 new code hinting capabilities, I'll hold down the Ctrl key and press the Spacebar.
04:13Dreamweaver CS5 brings up a listing of all of its known commands that start with the term PHP.
04:20I'll type IN and I'll find three items that I could add that have php and ini;
04:27I'll press the down arrow twice to move down the phpinfo.
04:31Notice that Dreamweaver CS5 gives you help automatically.
04:36This is the PHP project's own online help that's being displayed, and it'll
04:41tell you a lot about the different PHP commands that are available and how to use them.
04:45I'll press Enter to choose phpinfo, and then type in a closing parenthesis, I'm
04:52going to call the phpinfo function without passing in any values.
04:57Now I'll save the file, selecting File > Save, and then I'll look at the
05:01page using Live View.
05:04Now before you use Live View, make sure that you can see the browser toolbar,
05:09if you can't, you can right-click on any of the toolbars and choose this item
05:13Browser Navigation.
05:15The Browser Navigation toolbar will show you what the URL is that you're
05:18browsing to within Dreamweaver, click Live View.
05:22If you see the dialog box asking you to update the copy on the testing server,
05:26click Yes and then click Yes again for dependent files.
05:31On the right, you should see design view open up and show the resulting output to
05:36the browser. Go to the toolbar and click Design, and that will allow the Design
05:41view to take up the full available area.
05:44The phpinfo function outputs the current version number of your PHP server and
05:49all sorts of other configuration information.
05:52One of the most important things you should know, is the location of your php.ini
05:58file, that's the PHP configuration file.
06:02I'm working on Windows with WAMP server, so my PHP file is located in my Apache
06:072.2.11/bin directory.
06:11If you're working with MAMP on Mac, the location will be different.
06:15Now I'll go back to Code view and see the actual output.
06:18So in this exercise, you've created your first dynamic PHP page, you've
06:24embedded dynamic PHP server-side code in the page, and at runtime, the PHP server
06:31executes the phpinfo function and outputs a bunch of very complex information to the browser.
06:37Here's another way of executing the page through the external browser that I'll
06:41give you a little bit more information about what's going on.
06:44I'll deselect Live View, then go to the Preview button and choose my favorite browser.
06:51Once again I'll copy files to the server directory and here's the
06:55phpinfo display again.
06:57In the browser, I'll view the source. In Firefox, you can do this by selecting
07:02View > Page Source.
07:06I'll expand the size of the font so we can see it more easily, because I want to
07:11show you that that single function phpinfo actually outputs an entire web page,
07:17starting at this point with the doc type and going all the way down to almost
07:23the bottom of the page, to this ending HTML tag.
07:27This tells me that if you're using the PHP function, you don't need the rest
07:32of the HTML structure.
07:34So I'll close the browser, go back to phpinfo.php and I'll delete everything
07:40except the PHP command. I'll save the change, run the page in the browser again,
07:47once again copying files as needed. I'll view the source and this time I only
07:55see the output of the phpinfo page.
07:59As I'll show you in the other exercises, most of the time in your actual
08:04production pages, you'll be mixing your own custom HTML and cascading style
08:08sheets with your PHP commands to output information, but the phpinfo function
08:14is a critical tool that can help you find out what's going on, on your PHP
08:18server, which version of PHP you're running, and a lot of information about its
08:23configuration.
Collapse this transcript
Adding PHP commands with the Insert panel
00:00Dreamweaver gives you the ability to insert simple PHP commands fairly
00:04automatically, using either the menu or the Insert panel.
00:08For this demonstration, I'll use files in a copy of this site in the folder
00:1302_gettingstarted > 04_insertphpcode.
00:17And I'll work with this file, helloworld.php.
00:22This file already has a .PHP extension and when I look at it in Live View, which
00:30results in copying the file over to my server folder, and browse the file
00:34through the localhost URL,
00:37I'll see that the file is shown with the simple text "Hello World" in a content area.
00:42I'm going to show you how to replace that literal text with a simple PHP command.
00:48Here is the text inside a pair of <h1> tags.
00:50I'm going to remove that text, and then I'm going to use one of the most
00:55fundamental PHP commands,
00:57the echo command, to output a literal string into the browser.
01:02To do this from the menu, select Insert > PHP Objects, and then choose Echo, or if
01:10you prefer, you can use the Insert panel, switch to the PHP category, and then
01:16once again, choose Echo.
01:19I'll click once on the Echo selection. That inserts a PHP code block and adds the echo command.
01:26After the Echo command, you can add to the echo command any literal string or
01:31any variable or dynamic expression that will evaluate to a string.
01:35I'm going to pass in the value Hello World, wrapped in quotes.
01:40I'll save my changes and then I'll look at the file again in Live View.
01:44I'll exit Live View and then, enter it again.
01:47Notice that the file was once again being copied to the testing server, and then
01:51I'll go to Design View, and I'll see exactly the same text output.
01:56Now to see this in an external browser, I'll go to the Browser button in the
01:59toolbar, and I'll select my favorite browser -
02:03I usually use Firefox for testing -
02:06go through the copying dialogs, and once again there is the output.
02:10Now, here is the important thing to understand about the echo command.
02:13I'll look at the Page in the Source View, and here is the text that's being output by
02:18the echo command. By the time gets to the browser, it's just text.
02:24I'll go back and make a simple change to the code.
02:27I'll go to the Code View, and I'll change the text to Hello World from PHP.
02:33I'll browse the page.
02:35If prompted, I'll say Yes I want to save the file, and I want to copy it.
02:40And now the text is output in the browser, exactly as I typed it in the echo command.
02:45And once again, I'll show you Source View and show that that's the text that's
02:49output, and that the browser receives simple text.
02:52Again, the important thing to understand about PHP and all web application
02:56servers is that the commands that you execute that are a part of the
02:59server-based language, such as PHP, are executed on the server, and the browser
03:05doesn't know anything about them.
03:06The browser receives the resulting HTML markup, including any text that
03:12you output.
Collapse this transcript
Setting and outputting simple variables
00:00While most of this video series deals with PHP code that's generated by Dreamweaver,
00:05it's useful to know a little bit about hand-coding PHP.
00:09So I'm going to show you how to set a simple variable, and then how to output the
00:13value of that variable in a web page.
00:16I'll be working with files in the folder 02_gettingstarted > 05_variables, and
00:24I'll open the file in that folder, variables.php.
00:28Let's take a look at the existing code.
00:30In this file, there is just simple use of the echo command that's outputting the
00:34literal string Hello World from PHP.
00:37I'm going to show you how to set a simple variable that contains that same value.
00:41A variable is like a little bucket of information.
00:45All programming languages support them, but the way you declare and set the
00:49value of a variable in each programming language differs.
00:52You can set a variable anywhere in a PHP page, but wherever you set it, the
00:57variable will only be available from that point downward.
01:01So I'm going to place the cursor at the top of my page in Code View and then
01:05press Enter or Return a couple of times to make some blank space.
01:09And then I'll move the cursor up to the top of the page.
01:13Then I'll go to my Insert panel, and I'll choose the PHP category, and then
01:19I'll choose Code Block.
01:21And that adds a simple PHP code block.
01:23Then I'll press Enter a couple of times to make a blank line, and within the PHP
01:29code block, I'll set a simple variable, named Hello World.
01:33You can name your variables anything you want, but you should always prefix them
01:37with the Dollar sign.
01:38Notice when I type the Dollar sign into Dreamweaver CS5 that I get a list of a
01:43number of existing variable that are always a part of the PHP environment, such
01:48as COOKIE, ENV, FILES, GET, POST, and so on.
01:51We'll get to some of these later.
01:54For now, I'm creating my own variable, and I'll name it welcome.
01:59I'll set the value of the variable to "Welcome to my homepage," and I'll end the
02:04declaration with a semicolon.
02:07Notice as I type the Dreamweaver CS5 checks for syntax errors, and if the page
02:12is clean, it shows me the message, No syntax errors.
02:16If I remove something from the statement that makes it syntactically incorrect,
02:20Dreamweaver immediately shows that there is a syntax error.
02:24I'll put that code back in, and Dreamweaver removes the error message.
02:29To use that variable, I'll go down to the echo command where I'm outputting a
02:33literal string, and I'll remove the literal string, I'll type the Dollar sign
02:38and then a W, and Dreamweaver CS5 shows me my variable, $welcome.
02:44This is a new feature of Dreamweaver, the ability to give you hints as to the
02:48names of variables, functions, and other elements of your preexisting PHP code.
02:54I'll press Enter or Return, or click with the mouse, and that inserts the
02:59variable into my echo command.
03:01I'll save the changes, and then I'll use the external browser to look at the result.
03:08The value of the welcome variable is now output on the page, and because I
03:12placed the echo command inside <h1> tags, the text shows up as a title one.
03:18I'll View the Selection Source in Firefox, and I'll see that the value that's
03:25output to the browser is the simple text, because once again, the browser is not
03:30capable of interpreting and executing PHP code.
03:34So that's a look at how to set variables using simple assignments statements, and
03:40how to output the values of those variables using the echo command.
03:44You wrap both statements inside PHP code blocks and then all of the processing
03:49of the PHP commands happens on the server, and the resulting HTML markup is
03:54returned to the browser.
Collapse this transcript
Testing pages with Live view and Live Code view
00:00I've shown you so far how to execute PHP code on the server and then how to look
00:05in the browser to see what's returned from the server to the client.
00:09You can also do this in Dreamweaver using a feature called Live Code.
00:14For this demonstration, I'll use a set of files in the chapter 02_gettingstarted
00:19and in the folder 06_liveview.
00:23I'll set my site to point to that folder, and then I'll open the
00:27file variables.php.
00:30This file has a bit of PHP code at the top that sets a variable named welcome,
00:35and then down in the content area of the page, there is another PHP command that
00:39uses the echo command to output the value of the variable.
00:42When I click the Live View button on the toolbar, Dreamweaver copies the PHP
00:48file over to the server folder, and then shows the resulting output in Design View.
00:53Let's take a look at the Live Code feature.
00:56The Live Code feature shows the resulting output in Code View.
01:00This is very similar to what you get in the browser when you say you want to
01:04view the source, but you see this all right here in Dreamweaver.
01:09I'll click Live Code, and now take a look at the result.
01:12The initial PHP command up at the top of the page is stripped out, and the PHP command
01:18that's outputting the value of that variable is replaced with the resulting text.
01:23Now, I'll turn off the Live Code feature, and I'll see the original PHP commands,
01:28and turn it back on and see the output text.
01:32So the purpose of the Live Code feature is to allow you to see the resulting
01:36HTML that's generated at the server, by the combination of your HTML markup, your
01:42Cascading Style Sheets, and your PHP commands.
01:46You'll see the same result with JavaScript code.
01:49That is if you have any dynamic JavaScript code that's being executed in
01:52the client that changes the content of the HTML page at runtime, the Live
01:57Code feature will detect that and show with the browser is receiving, not
02:02what was sent to the server.
02:04It's an invaluable debugging tool that's available in Dreamweaver CS5.
Collapse this transcript
Using server-side includes
00:00Many PHP developers like to use a feature of PHP named Server Side Includes.
00:07This architecture lets you take reusable code that you're using in many PHP
00:11pages, and place them in files that are then included at runtime on the
00:15server in other pages.
00:17For this demonstration, I'll use a set of files in the folder
00:2002_gettingstarted > 07_includes.
00:24I'll point my site at that root folder.
00:27I'll start with this file, index.php.
00:31Let's take a look at this page in an external browser.
00:34I'll copy the file over to the server directory, and show you that the index.php
00:39has a navigational toolbar on the left, a logo up at the top,
00:44and these two bits of content together make up the page header.
00:47This header is used in multiple pages in the web site.
00:51Similarly, at the bottom of the page, there is a footer that contains a number
00:55of hyperlinks and information.
00:58Once again, this content is repeated on multiple pages.
01:01I'm going to show you how to take this reusable content, put it into include
01:06files, and then how to include them in multiple pages at runtime.
01:11First, I'll create the Include file.
01:14I'll go to my site header in the Files panel, right-click on it, and choose New Folder.
01:21I'll name the folder _includes.
01:24You don't need to include the underscore prefix on your folder names, but it's
01:28a common convention.
01:30After renaming the file, you might see it fly away,
01:33that is, disappear from the visible part of the screen.
01:36If that happens, just scroll up, and find it again.
01:39Right-click on the new _includes folder, and choose New File, and name the
01:44new file header.php.
01:47Then double-click on the new file to open it.
01:49This will be included at runtime into an existing PHP page, which already has
01:54the main HTML page structure,
01:57so you don't need this basic HTML page structure in the included page.
02:02So I'll select and delete all of the existing code.
02:06Then I'll go back to the homepage, index.php.
02:09I'll look at the page in Design View.
02:12I'm first going to take the content that includes the logo up in the upper-left.
02:17I'll click on the logo.
02:18Then I'll go to my tag selector, below the design area, and click on the div tag
02:23with an id of header.
02:26Then I'll go to Code View, and see what I've selected.
02:29Notice that that takes the div tag only with the id of header.
02:32What I really want is its wrapping tag, main header.
02:36So I'll hold down the Ctrl key on Windows, or the Command key on Mac, and press
02:40the Open Bracket key right next to the letter P. That expands the selection
02:45outward to include another parent tag.
02:48I'll cut that content to the clipboard, and go to header.php, and then paste it.
02:54Then I'll press Enter, because I'm going to be taking one more div tag that I
02:58want to place below it.
02:59I'll go back to index.php.
03:02I'll select the div with an id of mainNav.
03:05You can do this in Code View by placing the cursor, and then pressing Ctrl or
03:10Command, plus the Bracket key again, or you can go to Design View, and use the tag selector.
03:16Either way, you want to make sure that you've selected the entire div tag that
03:20contains all of the hyperlinks for the side navigation bar.
03:24Then once again, cut to the clipboard, go to the header, and paste.
03:29Then save your changes by pressing Ctrl+S on Windows, or Command+S on Mac.
03:35Then go back to index.php.
03:38Make sure you've left the cursor in the same location from where you cut that content.
03:42Then you'll add the PHP Include command.
03:46I'll go to the Insert panel, and select the PHP category, and I'll choose Include.
03:52You can actually choose either Include or Require in this position.
03:56These two commands do pretty much the same thing.
03:58They include a single page.
04:00But the difference is that if the Include page encounters an error, it will
04:04output an error message but keep processing the page;
04:08whereas the Require command, if it encounters an error, it will
04:11terminate execution.
04:13I'll choose the Include command.
04:15This results in adding a PHP code block and the Include function.
04:20You pass into the Include function the name and location of the file you want to include.
04:24You wrap this in quotes.
04:26So I'll type in a quote character, and then the name of the folder
04:30_includes/header.php.
04:36Then I'll close the string with a closing quote.
04:39Dreamweaver sees then that there are no syntax errors, and the error above the
04:43editing area goes away.
04:45I'll test my page in the external browser.
04:48I'll save the change, and preview in Firefox.
04:52This results in copying all of the files over to the server, including the new Include file.
04:57Then when the page is requested from the browser, the PHP server opens
05:01index.php, sees the Include command, and puts the pages back together at runtime.
05:08The result is that the page looks exactly the same as it did before.
05:11Now let's create a footer file.
05:14I'll locate my _includes folder in the Files panel, and create a new file.
05:19I'll name the new file footer. php, and double-click to open it.
05:24I'll delete all of the code, and then return to index.php.
05:29This time, I'll do my selections in Design View.
05:31I'll go to Design View, and scroll down to the bottom.
05:35I'll click anywhere in the footer area.
05:38Then in the tag selector, I'll choose div #footer.
05:41Then I'll go to Code View, and see what I've selected.
05:43I've correctly selected the entire footer.
05:47I'll cut it to the clipboard, go to footer.php, and paste, and save my changes.
05:54Then I'll go back to index.php.
05:57I'll go back to the Insert panel to the PHP category.
06:01Once again, add an Include command.
06:04This time, I'll include the new footer.php file, using the string
06:08_includes/footer.php.
06:13This time, I'm going to test only inside Dreamweaver.
06:17I'll take a look at the page in Live View.
06:19This copies the files over to the testing server.
06:21I'll look at the page in Design View.
06:25I'll scroll down to the bottom, and see that my footer is still intact.
06:29Now I'll go to Code View, and show you that in Code View, I'm seeing the
06:33original PHP command.
06:35But then, I'll switch to Live Code.
06:38That results in replacing the PHP Include command with the content that's being
06:43processed at the server and sent back to the browser.
06:48So that's a look at how to create includes.
06:50Once you've done this much, the next step will be to go through all of the other
06:54HTML pages and rename them with PHP extensions.
06:58For example, I'll exit Live Code and Live View, and
07:02then go to the Files panel, right- click on mission.htm and rename it.
07:08I'll rename it with a .php extension.
07:11Dreamweaver will detect all of the references to that page throughout the web
07:15site, and let's you update them.
07:17I'll do the same thing with resources.htm and tours.htm.
07:23Then I'll go through those pages, and replace the literal headers and footers
07:27with the references to the included files.
07:31Once you've finished this process, your web site will be much more
07:34maintainable in the long term.
07:36If you need to make a change to the navigational toolbar or the footer, you make
07:40a change to those PHP files, and copy them to your server.
07:45You don't need to do anything to the files that are including them at runtime.
Collapse this transcript
Navigating included pages with the Code Navigator
00:00The Code Navigator is a tool of Dreamweaver CS5 that lets you navigate from a
00:05top-level page to its included pages, such as CSS files, JavaScript files, and
00:12PHP Server Include files.
00:14For this demonstration, I'll use a set of files in the folder 02_gettingstarted
00:19> 08_codenav, and I'll point my site to that folder, and I'll open a file named mission.php.
00:26I'll take a look at this file in Code View, and show you that there are a couple
00:31of PHP Include commands.
00:33Up at the top, I'm including header.php, and down at the bottom, I'm
00:38including footer.php.
00:40The purpose of the Code Navigator is to allow you to navigate from one page to
00:44another very easily.
00:46In Dreamweaver CS5, up at the top, in the toolbar, you'll see icons for each file
00:51that's included in the main file.
00:53These allow you to jump to, for example, Cascading Style Sheet files, and
00:58Server Side Includes, such as my header and footer.
01:00But the Code Navigator gives you another simple way to navigate.
01:05I'll go back to the Source Code icon, which takes me to the main page, and
01:09then look at the page in Design View, and scroll down toward the bottom, where my footer is.
01:15I'm going to click anywhere in the footer and then wait two seconds.
01:19You'll see a little graphical icon show up.
01:22When you move the cursor over, you'll see this message, Click indicator to
01:25bring up the Code Navigator, and when you click it, you'll see a hierarchical
01:30display, showing you the name of the current page and the name of any includes,
01:35in this case footer.php.
01:37You also see a listing of your Cascading Style Sheet files and Cascading Style
01:42Sheet rules that might be affecting the currently selected content.
01:46I'll click on footer.php, and takes me to that included page.
01:51You can also get to the Code Navigator from Code View.
01:54I'll go to Code View and go to the first Include page, wait two seconds, and
02:00there's the Code Navigator icon.
02:02I'll click it, and there is the same display.
02:05You can also get to the Code Navigator from a Context menu.
02:08I'll right-click on the code and choose Code Navigator, and it gets me to the same place.
02:13There are also keyboard shortcuts and selections from the main menu.
02:17So the Code Navigator lets you easily move between a main page and any included pages.
02:23In theory, it should be recursive, meaning that you should be able to drill down
02:28from one included page to another, to another, and another.
02:32There are some limitations that Dreamweaver imposes, but for the most part it
02:36will let you go anywhere in your page hierarchy, regardless of whether the
02:40includes are on the client, such as with CSS files and JavaScript files, or on
02:45the server, such as the PHP Server Side Includes.
Collapse this transcript
3. Managing PHP Code
Using code hinting with PHP variables
00:00One of the most useful new features in Dreamweaver CS5 for PHP developers is code hinting.
00:06For this demonstration, I'll use a set of files in the folder 03_managingcode > 01_codehinting.
00:14There's just one file in this folder, phpinfo.php.
00:18It has the PHP info command.
00:21I'll run this file on the server by clicking Live View and copying the file over
00:25to the resting server, and show you that the PHP info command outputs
00:30information on the PHP server, such as the build date of the server, the
00:35operating system, the location of the PHP INI file, and so on.
00:40I'll exit Live View.
00:44The code hinting feature gives you a list of all of the commands in the PHP
00:48language, variables and functions that you have defined in your own file, and
00:53also a lot more information.
00:55I'm going to start in this exercise by showing you how to use code hinting on
01:00commands that are a part of PHP.
01:03I'll place the cursor before the PHP info command, and then I'm going to use a
01:08feature called the date function.
01:10The date function returns the current date and time on the server.
01:15I'll type in an echo command and then type in the word "date." To get to code
01:20hinting, press Ctrl+Space.
01:22It's the same keyboard shortcut, regardless of whether you're working on Windows or Mac.
01:27The date function takes one required argument and one optional argument.
01:32The required argument is a format string that designates how the date should be formatted.
01:38When you press Ctrl+Space, you not only a list of all of the function and
01:42variable names that have the word "date" in it, but when the item you want is
01:47selected, you'll also get documentation.
01:50I'm going to scroll down in the documentation and show you that it provides a
01:54list of all of the characters that you can use in your format string.
01:58So, for example, a lower d means the current day as a numeric value
02:04with leading zeroes.
02:05The uppercase D means a text representation of the day in three characters, such
02:10as Mon for Monday. And the lower case day is the day of the month without
02:15leading zeroes, again numerically.
02:17I'm going to output the current time,
02:20so I'll scroll down in the listing till I get to the Time section, and I'll
02:24show you that the letter g, in lower case means the 12-hour format of an hour
02:29without leading zeroes, and the letter I means the number of minutes with leading zeroes.
02:35You can use whatever non-alphabetical characters you want to format these values.
02:42So I'm going to place my cursor back into the code, and put in an opening paren
02:46and then a quote, then g for the hour, a colon and a lower
02:52case I for the minutes.
02:53I'll close that string with a quote, and then I'll close the whole thing with a parenthesis.
02:59I'll save my changes and then click on Live View.
03:02I'll update the copy on the testing server and show you the current time,
03:08which comes back as 7:06.
03:10You won't see your actual time unless you just happen to be in the right time zone.
03:15It's up to you to control the current time zone, and once again, PHP provides
03:20a function for this.
03:21I'll place the cursor before the echo command and make a new line.
03:25I'll once again type in the word "date," and press Ctrl+Space, and then I'll
03:30scroll down to the function, date_default_timezone_set.
03:34You pass a string into this function. To find out what the available strings are
03:39for this function, scroll down a little ways into the documentation, and you'll
03:43see a link for the list of supported time zones.
03:46I'll click there, and that opens a browser to the PHP documentation on the web.
03:52You do need an Internet connection at this point to see this information.
03:56Then from there, I'll click into America, and from there, I'll locate my particular
04:01time zone, which I'm going to set as America/Los_Angeles.
04:03I'll locate that string and copy it to the clipboard from the browser.
04:10Then I'll return back to Dreamweaver.
04:13I'll press Ctrl+Space, and I'll once again go down to date_default_timezone_set,
04:18and this time I'll press Enter. Then I'll type in a quote and paste in my time
04:23zone identifier, then a closing quote, a closing parenthesis, and a semicolon.
04:30Then after I've set the time zone but before I output the date, I'll put in
04:35another new line of code and echo, and then I'll output a literal string of
04:40The current time is:.
04:42I'll save my changes. Then I'll click over on the design area, and that causes
04:48Dreamweaver to prompt me to update the copy of my file on the testing server.
04:52I'll click Yes, and Yes, and there is the result.
04:56Now I'm seeing the current time in my time zone, or whichever time zone I've set
05:01in the date_default_timezone_set function.
05:04The goal of this exercise is to show you how to use the code hinting to help you
05:08find and insert long function names very easily, and also how to use the code
05:14hinting feature to get to the PHP documentation for the particular function
05:18you're interested in.
05:20The goal of this feature of Dreamweaver is to make it easier for those who like
05:23to do a little bit of hand-coding in PHP, to get to the features of the language
05:27that they need and insert the code correctly.
Collapse this transcript
Understanding PHP custom classes
00:00In addition to offering code hinting for PHP language elements, Dreamweaver CS5
00:06also gives you code hinting for custom classes.
00:09A PHP custom class is a way of creating reusable code.
00:13I'll start by creating a custom class, and then showing you how to use code
00:18hinting to use its features.
00:20I will be working with the version of files in the exercise files, in a folder
00:24named 03_managingcode > 02_hintingwithclasses.
00:29I will start in my _includes folder.
00:32I am going to create a custom class that encapsulates, or contains code to output
00:38the current time to the web site.
00:39I will go to the _includes folder and create a new PHP file.
00:44I will right-click on the folder and select new file, and I will name the new
00:48file DateUtility.php.
00:52When you create a file to contain a custom class declaration, you should always
00:57use an uppercase initial character, such as the D in DateUtility. That's a
01:02convention that PHP developers use.
01:04Now I will open the file, and just as with a Server Side Include, I will delete
01:11any existing HTML code.
01:13Just as with all PHP code, a PHP class declaration must be placed within a code block,
01:19so I will go to the Insert panel to the PHP category, and I will add a code block.
01:26Then, with the cursor inside the code block, I will press Enter a few times.
01:31Here is how you define a PHP custom class.
01:35You start with the word "class," then you type in the name of the class.
01:40By strong convention, the name of the class matches the name of the file, but
01:44without the .php extension.
01:47Then you put in a pair of curly braces.
01:50Within the class, you can define variables or properties, and functions or methods.
01:56I am going to define a single function named getCurrentTime.
02:00I will start with the word "public," then "function," then the name of the
02:03function, "getCurrentTime."
02:07After the name with the function, I will type in a beginning and an ending
02:09parenthesis, and then I will type in another pair of curly braces.
02:14The purpose of the getCurrentTime function will be to output the current time to the browser.
02:19I already have a little bit of code that does that
02:21that I created in a previous video.
02:24In this file set, I will find it in the phpinfo.php file.
02:28I will open that file, and then I will select and copy the three lines of code
02:35that set the current time zone and echo the current time to the browser.
02:39I will copy that code to the browser, then I will return to my class
02:44declaration, I will press Enter and then Paste. And I will select the two lines
02:51of code that aren't properly indented, then press Tab a couple of times to
02:56indent them within the function.
02:58So now this class has a public function that I can call anytime.
03:03I can use this class anywhere in my web site, and I will always get the
03:08same formatted value.
03:09I will save the file, and then I will open the file, footer.php.
03:16In order to use a class declaration, you first have to include it.
03:21So I will place the cursor up at the top of the file and make a couple of
03:24lines of empty space.
03:25Then I will go to the Insert panel, to the PHP category, and I will add
03:30an Include command.
03:33And I will include the file, DateUtility.php.
03:37If you want to include this file from a file in another directory, you can use a
03:41relative location, such as dots, dot-dots and names of folders.
03:46But because this file is in the same folder as footer.php, I just need to
03:51provide the file a name.
03:52I will save the file and move down to the bottom of the page.
03:56I will place the cursor after the paragraph tag with a class of phone, and I
04:00will create another pair of paragraph tags.
04:04I will make a little bit of empty space. Then I will go to the Insert panel
04:07and add a code block,
04:08and I will make a little bit of empty space within the code block.
04:11I am going to create a variable which is an instance of my custom class.
04:17The name of the variable will be dateutil, with the dollar sign prefix.
04:22Then to create an instance of my custom class, I will use this syntax:
04:27= new, and there is my custom class name, DateUtility.
04:30I will press Enter to select in and type in an opening and a closing
04:36parenthesis and semicolon.
04:38The dateutil variable is now an instance of my custom class, and I can call that
04:44custom class's functions, or methods, like this.
04:47I will go down to the next line, and I will type in $date.
04:53Dreamweaver shows me the name of the variable starting with date,
04:56dateutil, and I will press Enter or Return to select it. Then I am going to call
05:01a function, which is a member of the class.
05:04To call a member of the class, you use this syntax:
05:08->. It looks like an arrow.
05:11Dreamweaver automatically offers the name of the function in the class,
05:15getCurrentTime, using its code hinting capabilities.
05:18I will press Enter and then add a semicolon at the end of the line.
05:24So here are all the parts of the puzzle.
05:27At the top of the page, I used an Include command to include the class
05:32declaration, and then where I want the output to happen, I create an instance of
05:38the class and then finally call its function, and Dreamweaver, with its code
05:43hinting capability, helped me correctly name the class, and its function.
05:47I will save the change to footer.php. Then I will go to one of my top-level pages.
05:55I will use index.php,
05:58which is already including footer.php at the bottom of the file.
06:02I will look at the page using Live View, updating the files on the
06:08testing server as I go.
06:09I will look in Design View, scroll down to the bottom, and there is the result: the current time.
06:16So that's a look at how you can use code hinting to work with your own custom classes.
06:21Custom classes give you a way of encapsulating commonly used, or reusable code,
06:27and Dreamweaver CS5's PHP code hinting will help you make sure that you refer
06:32to the class names and its properties and functions correctly as you do your
06:36hand coding.
Collapse this transcript
Adding Zend Framework to PHP on Windows
00:00The new code hinting features in Dreamweaver CS5 allow you to integrate
00:05third- party, open source frameworks, and then using site-specific code
00:09hinting, you can configure Dreamweaver to allow you to do code hinting on the
00:13classes in these frameworks.
00:15Dreamweaver is preconfigured to work with three major frameworks.
00:18You can get to this feature through the menu by selecting Site >
00:22Site-Specific Code Hints.
00:25If you pull down the list under Structure, you will see that there are
00:28structures already in place for Drupal, Joomla!, and WordPress.
00:33I'll show you in this video how to install another third-party library called
00:37Zend Framework, which contains a lot of really valuable PHP extensions, and then
00:42I will use a few of these extensions throughout the course.
00:45Click Cancel to close the Site- Specific dialog and then take a look in the
00:49exercise files, under 03_managingcode.
00:53If you don't have access to the exercise files, no worries.
00:56I will provide a web site URL in a moment and show you where you can download it.
01:01If you do have access to the exercise files, locate the ZendFramework folder and
01:06copy it to the Clipboard.
01:08Then create a new folder on your system.
01:12I am going to create the folder right under my C drive and I am going to name it
01:16phpincludes, and then I will paste the ZendFramework folder into place.
01:21Now if you don't have access to the exercise files, you can download the Zend
01:27Framework from this web page:
01:30framework.zend.com/download.
01:33On this page, I will click on the Latest Zend Framework Releases link and then
01:39this is the link that I downloaded from, Zend Framework Minimal Package.
01:44There are a number of different links here, including the full package, the
01:47minimal package which I am using, and the Zend framework documentation.
01:51Extract the file that you download, copy the file to the appropriate place, and
01:57then name your folder the same as I have named mine, ZendFramework.
02:01The next step is to configure your PHP environment to use the Zend framework.
02:07If you are working on Windows with WampServer, go to the system tray icon for
02:11WampServer, then go to PHP and then load the file php.ini.
02:18It will open in a text editor, such as Notepad.
02:21If you are working on Mac with MAMP, here is how you can find out which
02:25php.ini file you are using.
02:28Go back to Dreamweaver and then create a file called phpinfo.php, where the
02:34code is very simple.
02:36It just has the simple phpinfo command.
02:40Run the page on the server through Live View or through an external browser and
02:45then take a look in the resulting output at the loaded configuration file.
02:50This will tell you exactly which copy of php.ini your PHP server is using, and
02:56then once again open it in any text editor.
03:00Now let's return to the php.ini file.
03:04Look for a setting called include_path.
03:07I'll press Ctrl+F - I am working in Notepad - and I will type include_path.
03:13If you are working on Mac in a text editor, press Command+F and then do the same thing.
03:18The first include_path you will find isn't the one you are looking for;
03:21it's in a comment section.
03:23So search again and this time you should find your way to the
03:27include_path settings.
03:29There are two, one for UNIX and one for Windows.
03:33If you are working on Windows, uncomment the include_path setting, and delete
03:37the C:\php\includes, leave the dot semicolon, and then include your
03:44ZendFramework folder like this, C:\ phpincludes\ZendFramework\library.
03:54You'll point to the library folder, and then in your PHP pages, you will
03:58explicitly include files from the ZendFramework, starting with the folder Zend
04:03and then walking down to the file you want to include.
04:05I will save that change.
04:09If you are working on Mac with MAMP, it will look like this.
04:12I have a copy of the Mac version of this file in this folder, so I'll open it in Dreamweaver.
04:17Once again, I will search for include_ path and in the MAMP version, you will see
04:22that the include_path is already uncommented, and all you need to do is point it
04:27to the appropriate folder.
04:28You should keep the setting that's in there - don't delete it - but on UNIX
04:32you separate the directories from each other with the colon character, not the semicolon.
04:37And then after you have made all of the changes to your php.ini files, you'll
04:41need to restart your server.
04:43For Windows, I will go to the WAMP Server Admin menu, and I'll choose
04:47Restart All Services.
04:50If you are working with MAMP, go to the MAMP application and once again
04:54restart your servers.
04:56So configuring Zend Framework is as simple as copying the ZendFramework file
05:00somewhere on your hard disk, and then changing the include_path in your PHP ini file.
05:06Once you follow those steps, you are ready to start using the Zend Framework,
05:10and in the following video I will show you how to set up site-specific code
05:14hinting, so you can easily use the framework's classes.
Collapse this transcript
Adding Zend Framework to PHP on Mac
00:00In a previous video, I described how to install and configure the Zend Framework
00:05into your PHP installation on Windows using WAMP server.
00:08In this video I'll describe how to do the same thing on MacOS X with MAMP.
00:13I'll assume that you're working with MAMP in its default configuration with the
00:18MAMP folder under Applications.
00:20If you have access to the Exercise Files that come with the course, you'll
00:24find a copy of the Zend Framework in the 03 managing code folder under Exercise Files.
00:29If you don't have access to those files, you can download Zend Framework from
00:33the Zend Framework website website at framework.zend.com/download/latest.
00:41Look for the Zend Framework minimal package.
00:44Click the free download link and follow the prompts.
00:47You can place the Zend Framework anywhere on your Mac hard disk.
00:51I typically copy it under the MAMP installation folder.
00:55So I'll do that in these steps.
00:57I have an alias to my MAMP folder here.
00:59It's under /Applications/MAMP.
01:00I'll go back to the 03 managing code folder and copy the Zend Framework to
01:07 the Clipboard.
01:09Then go to the MAMP folder and paste it in.
01:13The next step is to include the Zend Framework files in your PHP configuration.
01:18You do this by modifying the PHP.ini file.
01:23You'll need to be sure which version of PHP.
01:25ini is being used by your PHP installation.
01:29To do that, go to MAMP and click Open start page.
01:33From there click on phpInfo at the top.
01:37The phpInfo page will show you which PHP.ini is being used under
01:42Loaded Configuration File.
01:44My PHP.ini is under / applications/MAMP/conf/PHP 5.3/PHP.ini.
01:55I'll navigate to that folder in Finder.
01:58I'll start at my Mac hard disk root and go down to Applications , then MAMP,
02:07con, PHP 5.3, and here's the INI file I need to modify.
02:14You can open this with any text editor.
02:18Once you've opened PHP.ini, search for the string include_path.
02:24Working in Text Edit I've pressed Command+F, typed an include_path and
02:29then clicked Next, and I'll find that the first instance of that string is in a comment.
02:33I'll click Next again and this takes me to the actual setting.
02:38This is the default setting in the PHP.INI file provided with MAMP.
02:43It includes a dot, meaning the current directory of the currently executing PHP
02:47file, Then the paths are separated from each other or with a colon.
02:52In Windows, it's a semicolon.
02:54The following path refers to an area where you might add files in your MAMP installation.
03:00In fact, it refers to a directory that doesn't actually exist, but I'm going
03:03to keep it in that string and then add the correct path from my Zend Framework installation.
03:09I'll place the cursor after the current path and before the closing quote, then
03:13put in a colon, and then the path, / applications/MAMP/ZendFramework/library.
03:25Make sure you type it exactly as I'm showing here.
03:28It is case sensitive.
03:30Save and close your PHP. ini file and return to MAMP.
03:37Click the Stop Servers button to close down your servers.
03:40If necessary, type in your administrator password, and then once the servers
03:45gave shut down, click Start Servers to start them up again.
03:48The Zend Framework classes should now be available to your PHP runtime
03:53environment and as I'll show in subsequent videos, you'll be able to include and
03:57execute the classes where ever you need them in your PHP-based website.
Collapse this transcript
Using the Site-Specific Code Hints feature
00:00In order to show you how to configure site-specific code hinting for a
00:03third-party library, I'll work in this folder:
00:0703_managingcode > 04_sitespecific.
00:11I will set my site root to point to that folder.
00:14I have already installed the Zend Framework,
00:17a third-party PHP library and configure it so that it will work with PHP.
00:21I am going to configure Dreamweaver so that as I code my PHP in the editor,
00:27I will get code hints -
00:28that is, a list of available methods and properties of different classes in the library.
00:33I will go to the menu and select Site > Site-Specific Code Hints.
00:39The Structure list shows you that Dreamweaver is preconfigured with code hinting
00:43for three commonly used libraries:
00:46Drupal, Joomla!, and WordPress.
00:50I am going to be configuring a new library, so I will leave the structure
00:53setting at New from Blank. Then I will click the Browse button, and I will
00:58navigate to the location of my Zend framework installation.
01:03I am working on Windows, so I will go to C:\phpincludes;
01:08you should go to whichever folder you installed the Zend Framework in. Then I'll
01:12double-click into the Zend framework, to the library folder.
01:16That's as far as you should go.
01:18Don't click into the Zend folder;
01:20you'll select that in another step.
01:23Click the Select button and return to the Site-Specific Code Hints dialog.
01:26I am going to add references to folders that I want to scan for code hinting.
01:32I will click the Plus button, and I will click the Browse button, next to File/Folder.
01:37I will double-click the Zend folder.
01:40The Zend folder contains a number of subfolders that contain various classes.
01:45Although you can't see it in this dialog, there are many PHP files in this
01:50folder that will be included in your application files.
01:53I will click the Select button.
01:56Don't check the Recursive option for this folder.
01:59If you do, it will take a long time to scan the entire framework.
02:03The purpose of including this folder is to include the top-level PHP include
02:08files for the different classes.
02:11Next, click the Plus button for Extensions, and then click into the new extension
02:16item and type in ".php" and then click Add.
02:21So what you have said is that you want to scan this folder and not any of its
02:26subfolders for all.php files, and any classes that are found in those files
02:32should be included for code hinting.
02:35Next, you should include the folders containing specific classes you want to use.
02:40I am going to be using the Zend date class,
02:43so I will click the Plus button, I will browse again, I will double-click down
02:48to Zend, and then down to the Date folder, and then I will click Select.
02:54This time I do want to select Recursive. That will cause Dreamweaver to scan
02:59through all of the subfolders of this folder, and get all of the subclasses that
03:04the Date class is dependent on.
03:06Once again, I will click Plus and then add the .php extension, and click Add.
03:13So take a look at the selections.
03:15The Zend folder is set without recursion, the Date folder is set with recursion,
03:20and they both use the .php extension.
03:22I will click OK, and I will be prompted to save my edits as a preset.
03:27I will click OK again, and I will give my new structure a name of ZendFramework.
03:35By creating this as a preset, you will be able to apply this code hinting preset
03:40to other sites in the future.
Collapse this transcript
Using Zend Framework classes with code hints
00:00After configuring your third-party library, you can then use the code hints
00:04that are implemented with Dreamweaver to more easily and accurately do your PHP hand coding.
00:10For this demonstration, I'll use a version of my site in the folder
00:1403_managingcode/05_sitecodehints, and I'll point my site to that folder.
00:22When you configure site code hinting, a file is added to your site, named
00:27dw_php_codehinting.config.
00:31You can open this file in Dreamweaver, and you'll see that it's a simple text
00:35file that includes listings pointing to the absolute folder locations that
00:40contain your third-party files.
00:42If you're working on Mac OS X with MAMP and you placed the Zend Framework in the
00:47location I recommended, under the MAMP installation folder, in this file, you
00:52can change every instance of c:/phpincludes to /applications/MAMP.
00:59There is more information stored in the background;
01:01this file wasn't the whole story. But this is how you can tell that your
01:05particular code hinting setup has been added to the site.
01:09I'll demonstrate using code hinting by using your class named Zend_Date.
01:14The Zend_Date class is a PHP class that does a lot more than the standard PHP date class.
01:21I'll be adding the code in a file called DateUtility.php.
01:26This file is being included and used in a file called footer.php already.
01:31In the current version of the file, I'm setting the time zone and using the PHP
01:36date function to output the time in the current format.
01:40I'm going to add the use of the Zend_Date class here.
01:43The first step, before you can use any of the features of any PHP class, is to
01:48include the file that defines the class.
01:51You typically do this with a PHP command called include_once.
01:56I'll place the cursor at the line that has the class declaration and then create
02:00an empty line above it.
02:02Then I'll type in include_once, and then after an opening parenthesis, I'll add
02:08the relative location of the date class I'm interested in.
02:11I've already configured my PHP installation to automatically include anything in
02:16the Zend framework library.
02:18So all I need to de here is start off with the Zend folder, and then after a
02:23forward slash, name the class that I want to include, Date.php.
02:30If you're not sure of the names of the PHP files, take a look at the phpincludes
02:35folder, at the ZendFramework library folder, and then go to Zend.
02:41Down at the bottom, you'll see a whole listing of all the files that should be included.
02:46I'm including this one, Date.php.
02:50This file in turn includes all of the classes that are required: the DateObject,
02:56Locale, Format, and Math.
02:59It's up to the Zend framework to go and get all the resources it needs for all
03:03of the complex features that are implemented.
03:06I'll close these windows and return to Dreamweaver.
03:09So I've included the definition of the date class. Now, I can use it in my PHP code.
03:15I'll place the cursor inside the getCurrentTime function and press Enter to
03:20create a new line, and next, I'll create an instance of the Zend_Date class.
03:26I'll create a variable named zendDate -
03:29you can name this variable anything you want - and then I'll use the new keyword
03:34and then type the beginning of the class name.
03:37All classes in the ZendFramework library start off with the word "Zend."
03:41So I'll type in "Zend" and an underscore, and then I can scroll down and select
03:46the class that I want.
03:48I'm going to use Zend_Date.
03:50I'll type in an opening parenthesis, and I'm showing that there are three
03:55possible arguments, or values I can pass in:
03:58date, part, and locale.
04:00I'm going to ignore those properties for the purpose of this exercise, and
04:04not pass in any values.
04:07When you create a new instance of the Zend_Date class without passing in any
04:10properties, it represents the current date and time on the server.
04:15So, now I have a copy of the class, and I can call its functions.
04:20I'll place the cursor down toward the bottom of the function, after the last
04:24echo command, and I'm going to add a couple of echo commands that output some literal text.
04:29The first one will add a <br> tag.
04:32Make sure that you include semicolons at the end of every line.
04:35The next echo command will output some literal text: The current date is, and
04:42then I'm ready to use a feature of the Zend_Date class.
04:47Once again, I'll use the echo command, and then I'll use zendDate -
04:52that's the name of my variable - and then put in the dash greater than, and I'll
04:57see a whole listing of all the features of the Zend_Date class.
05:01You'll see that there is an enormous set of methods that you can use to
05:05manipulate and inspect various date values.
05:08First, I'm going to use the get method.
05:11The get method allows you to output the raw value of the zendDate object.
05:17I'll save the change, and then I'll open the file that's using my date
05:21utility class, footer.php.
05:24I'll look at this file in Live View, making sure that I update the server, and
05:30then I'll scroll down in the Live View and show that the current date is being
05:35output as a raw numeric value.
05:38This is the number of milliseconds from what's called the epoch date of the date object.
05:43Well, that's not exactly what I want to show the user.
05:46Instead I'd like to show them a friendly date output.
05:50So I'll exit Live View and go back to my code, and I'll go back
05:54to DateUtility.php.
05:58Instead of using the get method, I'm going to use another method called toString.
06:03The toString method, once again, can take a few different arguments:
06:06a format, a type, and a locale.
06:08I'm going to use a format this time of MMMM and a space, then a lowercase d, a
06:16comma and a space, and four Ys.
06:20These are masking values that mean the full name of the month, the date as a
06:24numeric value without padding, and a four-digit year.
06:29I'll save those changes and then go back to footer.php and look at the files
06:34in Live View, copying them to the server, and here is the result of using the Zend_Date class;
06:40I'm now getting a nicely formatted date.
06:42You'll find that the utility classes in the Zend framework are much more
06:46powerful than their raw equivalents in the PHP core libraries.
06:51Many developers like using the Zend framework only for these utility classes,
06:56while other developers like to use the entire capability of the Zend framework,
07:00which allows you to build complex, well-architected applications, using an
07:05application architecture known as Model-View-Controller, or MVC.
07:10However you use the Zend framework, Dreamweaver CS5, through its site-specific
07:15code hinting, will help you get your code right the first time, both for the Zend
07:20framework and for any other third- party PHP libraries you decide to use.
Collapse this transcript
Managing reusable code with the Snippets panel
00:00Dreamweaver CS5 offers another feature for managing your code, where you want to
00:05use the code over and over again.
00:07It's called the Snippets panel, and it's been a part of Dreamweaver for quite a while.
00:12For this exercise, I'll use the version of my site in the folder
00:1503_managingcode\06_snippets.
00:20The Snippets folder is located in the same panel group as the Files panel.
00:25It's populated with some default snippets, including commenting, footers, form
00:31elements, and many others, but you can add your own snippets quite easily.
00:38For this exercise, I'll start with the file footer.php that's in the
00:42_includes folder of my site.
00:43I'll look at the file in Code View in fullscreen and scroll down to the dateutil section.
00:51I'm going to take a few elements of this php code and make them into a
00:55reusable code snippet.
00:57I'll start with the PHP Include command up at the top. I'm going to move the
01:01code around a little bit to get the code ready to use in a code snippet, but I
01:06won't save the changes to this file;
01:08I'm only going to use it as a resource.
01:12I'll first select the include command from the first php code block, and I'll
01:17copy it to the clipboard.
01:19Then I'll go down to the other php code that's calling the DateUtility class.
01:24I'll place the cursor within the php code block and press Enter, and then paste
01:30in the Include command.
01:32Then I'm going to change the indenting of this code.
01:36I'll select the entire code block and then press Shift+Tab until all of the code
01:42is aligned left in the page.
01:45The purpose is just to strip out all the tabs before I create the snippet.
01:50I'll leave the code selected, and I press F4 to show my panels again.
01:56Then I'll go to the Snippets panel.
01:58Within the Snippets panel, you can add a new snippet to any of the existing
02:02folders, or you can create your own folder.
02:06I'll right-click in the panel, but not on any of the folder icons, and choose New
02:10Folder, and I'll name my new folder PHP.
02:13Then I'll right-click again and choose New Snippet.
02:18The code that I'd already selected in the editor area is automatically copied
02:23into the snippet dialog.
02:25You can also manually copy and paste, if you like.
02:28I'll name my new snippet Get Current Time.
02:32You can select your snippets to one of two types.
02:35If you choose Wrap selection, you'll be inserting code before and after selected code.
02:42If you choose Insert block, that means you're inserting all of the code as a single block.
02:47That's the type that I want to use.
02:49In the Description, you can type in anything you want.
02:52I'll type in, "Use my custom DateUtility class" and click OK.
03:01Anytime you want to use that code, you'll have it available in your Snippets folder.
03:06I'll go back to footer.php, I'll go back to the top of the page, and I'll remove
03:12the php code block at the top, and I'll go down to the bottom and remove that
03:17php code block as well.
03:19Now, in the future, if I want to use the snippet, all I have to do is make a
03:23little bit of space, then go to the Snippets panel and then double-click the
03:28snippet, or drag it where I want it to go.
03:31The Snippets panel allows you to build up a collection of common php code or
03:36HTML or JavaScript code, whatever you like.
03:39Unlike the site-specific code hints, which is site-specific, the Snippets panel
03:44saves your content for all of your sites.
03:47So if you come up with a good bit of code that works on one site and you want to
03:51be able to easily use it on another site, store it in the Snippets panel.
03:55Later on, you'll be able to use that code wherever you need it.
Collapse this transcript
4. Creating a Database
Understanding relational databases
00:00MySQL is an example of a relational database engine.
00:05It manages data in multiple tables and columns, and gives you the ability to
00:09join these tables together at runtime in SQL statements.
00:14It's important to understand a few basics about the nature of databases.
00:19Data is stored in tables.
00:21In this example, data is stored for a library in a number of tables, including
00:26Authors, Books, Customers, and Checkouts.
00:30Each of the tables manages data for a particular entity.
00:33For example, the Authors table manages data for each author.
00:38You define the table with multiple columns.
00:41Columns, also known as fields, represent the individual elements of data in
00:45a particular entity.
00:46When you design your tables, it's very important to include a single column,
00:51known as the primary key.
00:53In this table, the authorId is the primary key.
00:56The asterisk indicates this.
00:59Then each of the other columns represents a particular bit of data.
01:02For example, an author might have the firstName, the lastName, and the dateOfBirth.
01:08The authorId in MySQL is commonly set up as an integer, or numeric value, which
01:13means that when you add a new record to the table, MySQL assigns the next
01:18available number for the primary key column.
01:20You should design your web sites so that the user never sees this primary key
01:24explicitly on the screen.
01:26It's a meaningless value, so that the user doesn't have to enter the value or
01:30take any responsibility for it.
01:32It's completely managed by your web site, by your PHP code, and by your MySQL database.
01:39A well-designed relational database structure is said to be normalized.
01:44That means that you don't repeat data, but instead break it up into different
01:47tables, so it can easily be joined together as needed at runtime.
01:52As mentioned previously, each table should have a primary key.
01:56The value for each row in the primary key column uniquely identifies that row,
02:01so that if you have a row, say, with a value of 5 in the primary key, there will
02:05be no other row with that value.
02:08This makes it possible to select data from the table very easily.
02:12Most tables have single column primary keys.
02:15For example, an author's table would have an authorId, a book's table would have
02:20a bookId, and so on.
02:22You don't have to use that naming convention, but it's the one I typically use.
02:26There are also sometimes tables with multiple column primary keys, where two or
02:31more values together make up a unique value.
02:35I won't use any of those tables in the sample database for this video series,
02:39but you will see them occur in more complex database structures.
02:43In order to join tables together, you can add foreign key columns.
02:48A foreign key column in one table would match the primary key column in another table.
02:53That would allow you to join them together as needed.
02:56Here is a way to visualize the relationship between two tables.
03:00You create the relationships between primary keys in one table and a foreign
03:05key in another table.
03:07In this table, there are four columns named bookId, title, authorId, and isbncode.
03:14The asterisk indicates that bookId is the primary key for this table.
03:19authorId is also a numeric value, but it's not unique in this table;
03:24instead, it's designed to join this table to another table.
03:28This table would be the Authors table.
03:31It would also have four columns perhaps, with column names of authorId,
03:36firstName, lastName, and dateOfBirth.
03:38This table's primary key is authorId, indicated by the asterisk.
03:43Assuming that there are values in the two tables, Books and Authors that match
03:47each other, you would join them together at runtime by matching the values in
03:51the authorId columns of both tables.
03:55You would do this with an SQL statement.
03:58This is one available syntax for joining tables together.
04:01The SELECT clause indicates which columns from each table are going to be
04:05included in the recordset returned from the database.
04:08The FROM clause uses a JOIN operator to link the two tables together.
04:14The ON clause indicates which columns should match each other.
04:18The operator JOIN means what we call an inner join.
04:22That means that values will only be returned where there are matches between the two tables.
04:28You can also use outer joins, indicated by the phrases LEFT JOIN or RIGHT JOIN.
04:33That means that you're including data from one table regardless of whether there
04:37is a match is in the other table.
04:39Again, for the sake of simplicity, in this video series, I'll only use inner
04:43joins indicated by the JOIN operator.
04:46So this SQL statement will return four columns,
04:49the title and isbncode from the Books table, and the firstName and lastName
04:54from the Authors table.
04:56These values will be returned in a single recordset, and only where there would
05:00be matches between the authorId values in both tables.
05:04There is a lot more to know about relational databases, and normalizing your
05:08database structures,
05:10but if you understand these simple principles, you'll be able to follow all of
05:14the exercises in this video series, and
05:17you'll be able to accomplish about 80-90% of what we commonly do in dynamic web
05:22applications built with PHP and MySQL.
Collapse this transcript
Creating a MySQL database in phpMyAdmin
00:00Throughout the remainder of this video series, I'm going to be using a database
00:04that's built and stored in the MySQL database engine.
00:08I'll show you how to define a database from scratch first in phpMyAdmin,
00:13a web-based application that's included with both WAMP server on Windows and MAMP on Mac.
00:19Then in another video, I'll show you how to import an existing database from a script.
00:25To start up phpMyAdmin on Windows, go to the system tray icon, and then go to phpMyAdmin.
00:32If you're working on MAMP with Mac, go to the MAMP homepage, and then click on phpMyAdmin.
00:39On the phpMyAdmin homepage, click into Create new database, and then type in the
00:45name of the database you want to create.
00:47Your database name should not have any spaces in it.
00:51If you want to represent a space, use an underscore character,
00:54type the name of the database, and click Create.
00:58You're taken to a screen to create tables.
01:02You can have as many tables as you want in your database.
01:05Each table can have as many fields or columns as you need.
01:08In this initial database, I'm only going to have one table.
01:12It'll be named people.
01:14Set the initial number of fields.
01:16If you don't get this exactly right, it's no problem.
01:19You'll be able to add fields later on.
01:22I'll set my initial number of fields to 3, and click Go.
01:27On this screen, you're asked to define the fields or columns in your database.
01:32The first field should always be a primary key.
01:35I typically set the name of this column with the name of the entity that's
01:39being stored in the table, such as person for the people table, and then I
01:44append Id to the end of it.
01:46So the name of my primary key column will be personId.
01:51In MySQL databases, it's very common to set the primary key column as an
01:56integer, and then to add the AUTO INCREMENT property.
01:59That means that each time a new row or record is added to the table, the next
02:04available numeric value will be assigned to the table automatically.
02:08I first have to say that this is a primary key.
02:12You do that by setting the Index property to PRIMARY.
02:16Then I'll check the AUTO INCREMENT property.
02:18The other two columns will be named firstName and lastName.
02:23They'll both be set to variable character, or VARCHAR columns.
02:28VARCHAR columns can take text values.
02:31I'll set them each to VARCHAR.
02:35Then I'll set the available length for the columns to 50 characters each.
02:39That means that that's the longest available value that you can put into the field.
02:45Finally, I'll set the Storage Engine for this table.
02:48The Storage Engine indicates how the table will be physically stored on disk,
02:53and also what its capabilities will be.
02:55The default is a storage engine named MyISAM.
02:57MyISAM is an incredibly fast storage engine. It's the default.
03:05When you set a table up as MyISAM, you don't get transactional capability -
03:09I'll give you an explanation of what that means in a moment - but you do get very
03:13fast storage and retrieval.
03:16If you need transactional capability, meaning the ability to commit and roll back
03:20transactions, you can instead select the InnoDB engine.
03:25As with other settings, if you don't set this exactly the way you want it
03:28initially, you can change it later.
03:31I'll accept the default of MyIASM.
03:34Then, down at the bottom of the screen, I can click Save, or if I click Go, I can
03:39add additional fields or columns.
03:41I'll click Save, and that creates my table.
03:45On this screen, you're shown the actual SQL code that was used to create the table.
03:51Also in the table structure, you can see what the columns are, their data types,
03:56and their properties.
03:57If you need to edit any of these columns, you can click on the Edit icon,
04:01represented by a pencil, and
04:03you'll be taken to this data entry form.
04:06If you click Save, you'll see the resulting SQL statement that was used to make the change.
04:11If you need to add fields, you can use the form down in the middle.
04:15You can add fields to the end of the table, or after any of the existing fields.
04:19If you need to completely drop the table, or delete it, you can click the Drop icon.
04:25Be careful with this.
04:26If you drop a table or a database, there is no backup.
04:30You'll need to create it from scratch later.
04:33Once you've created the table structure, you're ready to add data to the table.
04:38I'll show you how to do that in a separate video.
Collapse this transcript
Adding data in phpMyAdmin
00:00Once you've defined a database structure, you can add data to the
00:04database through phpMyAdmin.
00:06For this demonstration, I'll use the database structure that I've already
00:09created in a previous video.
00:11The name of the database is mydatabase.
00:15From the homepage of phpMyAdmin, I'll click into the database.
00:19The database has a single table, named people.
00:22Some of the icons will be disabled.
00:25The Browse and Search icons are both disabled currently, because the table
00:29doesn't have any data.
00:31To insert some data, click the Insert link, the fourth icon from the left.
00:37You're taken to a screen where you can insert multiple rows.
00:41I'm going to add data for the firstName and lastName columns.
00:46I won't add data for the Id column, because that's an auto incrementing primary key.
00:51I'll click into the firstName, and type a value of Davey, and the lastName will be Jones.
00:57Then I can click Go immediately, or I can click down into fields in the second
01:02data entry form and insert multiple rows.
01:06For the second row, I'll set the values as Melissa, Smith.
01:11Notice that as I type values into these fields, the Ignore check box was
01:15automatically deselected.
01:18To insert both rows at the same time, click the Go button.
01:22By default, you'll Go back to the previous page.
01:25But if you have more data to enter, you can instead choose Insert another new row.
01:31I'll leave these settings at the defaults and click Go.
01:35The resulting SQL statement that adds the data to the database is listed here.
01:40I can browse the table by clicking the Browse icon in the Action column.
01:44I'll see that my data was successfully added to the table.
01:47The auto incrementing primary key column personId has values of 1 and 2, the
01:53next available values when I inserted the data.
01:56The nature of a primary key column is that its data should uniquely identify
02:01each row, and should be meaningless, meaning that the user shouldn't care about
02:05what the primary key is.
02:07So you can add as much data to your MySQL database tables as you need to
02:11through phpMyAdmin.
02:13If you want to edit the table, you can go back to the Table link, which you'll
02:17find up at the top of the screen.
02:20From there, you can edit, or you can delete individual records, or you can
02:24select multiple records, and edit or delete them from there.
02:28I'm not going to use this particular database and database table in the rest of
02:32the video series for the exercises;
02:35instead, I'll be using a database table that's defined in an SQL Script.
02:40I'll show you how to import that script through phpMyAdmin in the next video.
Collapse this transcript
Importing a completed database from a script
00:00In the exercises in the remainder of this video series, I am going to use a
00:04database that I have defined in an SQL script file.
00:08If you don't have access to the exercise files, you can find a copy of this
00:12database script in the free exercise files available on the lynda.com web site
00:17with this video series.
00:19If you have access to the exercise files, you'll be able to import the database
00:23quickly and easily in phpMyAdmin.
00:26You'll find the SQL file in the 04_createdatabase folder, under Exercise Files.
00:32It's named explorecalifornia.sql.
00:36You can open this up in any text editor.
00:38I am using TextPad on Windows.
00:41I am first going to walk through the database structure and show you how the
00:45database is defined.
00:46In the top of the SQL file, there are some comments that indicate the character
00:51set, connection, and names.
00:55Then the table structures and data are added.
00:58For each table there is a DROP TABLE command and then a CREATE TABLE command.
01:04This allows you to run the script, and it will wipe out any existing versions of
01:08the database tables and then create the new ones.
01:12The first table is named admin.
01:14It has three columns, called adminId - the primary key - userName and password.
01:20userName and password are both variable character columns.
01:24The primary key is adminId, the engine for the table is MyISAM, and then the
01:30character set and AUTO_ INCREMENT properties were set.
01:34The AUTO_INCREMENT is always set to the next available numeric value for the table.
01:39There is one Insert statement that adds a single row to the table.
01:42The primary key is set to a value of 1, and so the next available primary key would be 2.
01:49So that's the admin table.
01:51I'll be using that in exercises about authenticating users on databases.
01:56The next table is named explorers.
01:58Once again, it has a Primary Key column.
02:01This time it's named explorerId.
02:02Then it has a whole series of columns, such as firstName, lastName, and so on.
02:08Most of these are variable character or text columns.
02:12There is one column though, named dob, for date of birth, that's set as a date column.
02:18There are three existing records in the explorers table with primary key values
02:22of 1, 2 and 3, and so the AUTO_INCREMENT is set to 4.
02:27The next table is named packages and refers to tour packages.
02:32It has a primary key named packageId and three variable character columns.
02:37And then there are 9 records names Backpack Cal, California Calm, and so on.
02:44If you are setting up this database from scratch, you can add any values you
02:47want into these columns.
02:49The next column is named states, and it's a list of the states of the union.
02:54It has two columns, named stateId and stateName.
02:58The first column is set as the primary key, but in this case there is not an
03:02AUTO_INCREMENT column because it's a text-based column.
03:07With the states table, the first value in the each row is the two-character
03:11abbreviation for the state, and the second column is the name of the state.
03:15There are 51 records in this table, including 50 for the states themselves and
03:21one record for the District of Columbia.
03:23I'll be using this table in an exercise about data entry forms, and I'll show
03:27you how to take the data from this table and display it in a pulldown list that
03:32lets the user select a state.
03:33I'll scroll down a bit to the next table, which is named tours.
03:39The tours table has a primary key of tourId and a packageId, which is a foreign key.
03:46This column, packageId, lets you relate the table to the packages table, using a
03:51primary key-foreign key relationship.
03:53Most of the other columns in this table are variable character or text columns,
03:58but there is one column named price which is set with a data type of double.
04:02A double is a numeric value that allows fractional values.
04:06The double type is very commonly used in MySQL to represent currency values.
04:11There is another column that's not text-based.
04:13It's called length, and it's in integer value.
04:16This is the number of days for each tour. And then there were 20 something
04:20records that are provided for that table.
04:22So that's a look at the database structure.
04:25I'll show you how to import it.
04:27I'll go to phpMyAdmin.
04:34Before I can run the script, I need to create a new database, so I'll click
04:38into the Create new database field and type in "explorecalifornia" and then click Create.
04:48Once I've created the database, I can import the script.
04:52I'll click the Import button at the top. Then I'll Browse and select the SQL
04:57file from the 04_ createdatabase folder of the exercise files.
05:05After selecting the file, I'll click Go, in the lower-right corner.
05:10It takes only a second or two to execute the script and create the
05:13database structure and data.
05:15I'll click into the first table admin, and show you that there is one row, with
05:20a userName of explorerone and a password of password.
05:24I'll click into packages and show you that there are 9 records,
05:28states, and show you that there are many records for the various states,
05:32and tours.
Collapse this transcript
5. Using Bindings and Server Behaviors
Defining a Dreamweaver database connection
00:00In this chapter of the video series, I am going to describe features of
00:04Dreamweaver CS5 that allow you to easily connect to a MySQL database and
00:09retrieve and display data with generated PHP code.
00:13I'll be working in a version of this site in the exercise files, and if you have
00:17access to the exercise files, you can follow along.
00:20I'll go to the menu and choose Site > Manage Sites.
00:24I'll Edit my site, and then I'll set my local site folder to the folder
00:3005_bindingandbehaviors, under the exercise files.
00:34In previous chapters, I switched to a new site for each exercise.
00:39In this chapter, all of the exercises will be done in a single set of files,
00:44but I'll use a new file for each exercise, so I'll only need to change the site
00:48once for the entire chapter.
00:51I'll click Select and then click Save, and then click Done, and if you see any
00:56other messages along the way, click OK to clear them.
00:59The first step in connecting to your database is to define a
01:03database connection.
01:04You do this through the Databases panel.
01:07You can get to this panel through the menu, by selecting Window > Databases, or
01:12you can press the associated keyboard shortcut, or if you already have the panel
01:16in your workspace, you can go to it directly.
01:18I am working in the App Developer Plus workspace, and the Databases panel is
01:24docked in the right section.
01:26I'll open the Databases panel and then click the Plus button.
01:30If the Databases panel is disabled, check to make sure that you have a PHP file
01:35open and that Live View is turned off.
01:39When you're working with PHP in Dreamweaver CS5, you're only allowed to
01:43connect to MySQL databases.
01:45So I'll choose the only available item, MySQL Connection.
01:49You can set the Connection name to anything you like.
01:52I typically set it to the same as the database name itself.
01:56So I'll set my Connection name as explorecalifornia.
02:01The MySQL server entry should be pointed at the location of your database server.
02:05I am working with a copy of MySQL on my local system, so I'll type in "localhost."
02:11If you're working with a copy of the database that's on another machine, you can
02:15provide either the DNS name or the IP address.
02:19Next I'll select a User name.
02:22When you install WAMP server or MAMP, the default administrative username is
02:27root, and that's what I'll use.
02:29In a production environment, you'll have a unique username.
02:33The password will differ depending on whether you are working in MAMP on Mac or
02:36on WAMP server on Windows.
02:39If you're working on Mac OS X with MAMP type in the word "root," again, in all
02:43lowercase. If you're working on WAMP server on Windows, leave the password blank.
02:50Now click the Select button.
02:52You should see a list of the available databases in your database server.
02:57Depending on whether you're working on MAMP or WAMP server, you'll see either 4 or 5 databases.
03:03Choose explorecalifornia and click OK. Then click Test.
03:08This step verifies that Dreamweaver can connect to your database.
03:12If you're working on a WAMP server with a blank password, you'll see
03:16this warning dialog.
03:17If you are working on MAMP, you won't.
03:20If you see this warning dialog, click OK and then click Test again.
03:25And now, regardless of whether you're working on Mac or Windows, you should see
03:29the dialog, Connection was made successfully.
03:32Click OK and then click OK again.
03:35If you have any trouble with this part of the process, make sure that you can
03:39open phpMyAdmin and see the database from there, and then come back to
03:43Dreamweaver and try creating the connection again.
03:46When you define the connection, a file is automatically created in your site.
03:52It's placed in a folder named Connections, which you'll now find in your Files panel.
03:57If you don't see the Connections folder, click the Refresh button in the
04:00Files panel's toolbar.
04:03Once you see the Connections folder, open it up, and you should see a file named
04:07explorecalifornia.php.
04:10Double-click on the icon next to the file name to open it, and then if it opens
04:15up in Design View, switch to Code View.
04:18This file works by setting a number of variables and then using a PHP function
04:22called mysql_pconnect.
04:25Those variables are passed in to create the connection.
04:28The variable explorecalifornia represents the connection itself, and it will be
04:33used in any PHP pages throughout your web site, to connect to the database in
04:38order to retrieve or update data.
04:40The four variables are the hostname, which is set to localhost, the database
04:45explorecalifornia, the username root and the password, which will either be a
04:50blank value for Windows or the word "root" for Mac.
04:54To change the connection definitions, you can either edit this file directly, or
04:59if you prefer, you can go back to the Databases panel and double-click on the
05:03database, and that will reopen the MySQL Connection dialog.
05:08You can make changes here and click OK, and the connection file will be recreated.
05:13So that's a look at how to define your database connection.
05:16You go through the Databases panel, provide all of the required parameters,
05:21and the resulting file is stored in the Connections folder, which is stored in
05:25the site root.
Collapse this transcript
Building a simple recordset
00:00Once you have defined a database connection, you're ready to retrieve data from
00:04your MySQL database.
00:06Dreamweaver makes it easy to build simple SQL statements to do this work for you.
00:11SQL stands for Structured Query Language, and it's the standard that's used to
00:16communicate with the database from any application environment.
00:20To get started with SQL, open any PHP file.
00:23I am working with the file simplers.php, which you'll find in the root folder of this site.
00:30In the Bindings panel, there is a Plus button that lets you create what
00:34Dreamweaver refers to as a binding.
00:36A binding is a definition of dynamic data.
00:40I'll click the Plus button and choose Recordset (Query).
00:45The Recordset dialog box has two modes:
00:48Simple and Advanced.
00:50If this is the first time you've used this dialog, you'll see the Simple version.
00:54You enter the name of the recordset, select a connection, choose a table in that
01:00database, and then supply other parameters.
01:04There is a button labeled Advanced, and when you click that, you're taken to the
01:08Advanced version of the Recordset dialog.
01:10I am going to start with the Simple version.
01:13You can name your recordset anything you want.
01:16I typically prefix my record sets with the characters rs, so I am going to
01:20name this rsPackages.
01:23Then I'll pull down the Table list and choose the packages table.
01:27You'll see a listing of the available columns in the table.
01:31If you'll leave the Columns selection set to All, that means you're retrieving
01:35all of the columns in the entire table.
01:38If you prefer, you can choose the Selected radio button, and then holding
01:42down the Ctrl key on Windows or the Command key on Mac, you can click on the columns you want.
01:48I'll choose these three columns:
01:49packageTitle, packageDescription, and packageGraphic.
01:53Now, I am going to test my recordset by clicking the Test button.
01:58That shows me the data that's returned from the database.
02:02I'll click OK to close the dialog, and then I'll also add a Sort parameter.
02:07I'll pull down the sort list and choose packageTitle, and then I'll leave this
02:12second option set to Ascending.
02:14Now I am ready to insert the recordset into my current web page.
02:19I'll click OK, and I won't see any changes to the page in Design view.
02:24But I'll go to Code view and expand to fullscreen by pressing the F4 key, and
02:30I'll see that a whole bunch of PHP code has been added to my page at the top.
02:35First, I'll see a require_ once directive that includes the
02:39explorecalifornia.php file;
02:42that's the file that defines my database connection.
02:44Then there is a sequence of code that creates a select statement.
02:48A select statement in SQL retrieves data from the server.
02:53This select statement is retrieving the three selected columns packageTitle,
02:57packageDescription and packageGraphic from the packages table, and the order by
03:02clause is sorting the data by the title field.
03:06That string is my SQL statement.
03:08The next line of code executes the query by calling a PHP function
03:13called mysql_query.
03:15It passes in the query string and the connection.
03:19This little bit of code, starting with the phrase, "or die," means that if the
03:23query doesn't work for some reason, then the PHP page should be terminated.
03:29If everything goes well, at that point, we start fetching data by calling a
03:33function called mysql_ fetch_association, or assoc.
03:38And finally, a variable named totalRows_ rsPackages is created, which is based on
03:43the function mysql_num_rows.
03:47We're passing in the recordset and getting back the total number of rows in the recordset.
03:52So, all that code taken together executes the query, retrieves the data
03:57from the server and stores it in a set of variables, which you can use in your PHP pages.
04:03I'll show you how to display the data in various ways in some other exercises,
04:08but I'll also point out one last bit of code that's placed at the bottom of the
04:12page and is very important.
04:14It's called mysql_free_result.
04:17This releases the reference to the recordset in the PHP server's memory.
04:22And it makes sure that you are releasing any memory that's used by storing those
04:26record sets when the current page is finished processing on the server.
Collapse this transcript
Building an advanced recordset
00:00Dreamweaver CS5's recordset builder function can build either simple recordsets,
00:05which retrieve data from a single table, or if you have a little bit of knowledge
00:10of SQL, you can use the advanced recordset builder.
00:14I'm going to be working in a file named advancedrs.php.
00:18For this demonstration, I'll use the file advancedrs.php, which you'll find in
00:23the root folder of the current side.
00:26You build an advanced recordset by going to the Bindings panel, clicking the
00:31Plus button, and choosing Recordset or Query, and then click the Advanced button.
00:37The advanced recordset builder requires a little bit of knowledge of SQL.
00:42Whatever you know how to do with SQL, you'll be able to do here.
00:46I'm going to name this recordset rsTours, and then I'll go down to the Tables
00:51list, which you'll find in the Database items pane.
00:54I'm going to build a recordset that joins or links two tables together:
00:59packages, and tours.
01:02The packages table has a packageId, primary key column, and three descriptive
01:06columns for the Title, Description, and Graphic.
01:10The tours table also has a primary key column, named tourId, and has a
01:16foreign, named packageId.
01:18I'm going to use the primary key and the foreign key to join these tables
01:23together in an SQL statement.
01:26I'll use the recordset builder to help me build this statement.
01:29I will start with the tours table.
01:32For each column that I want to include in the data returned from the server,
01:36I'll click on the column and then click the Select button.
01:40I'll start with the primary key column, tourId, and I'll click Select, and I'll
01:45see in the SQL statement that two tables are included but only one column.
01:50I'm going to clean this up a little bit by removing the admin table, and then
01:55I'll test my query to make sure that it's valid, and I'm getting back this
01:59single column from the one table in the query.
02:03I'll click OK to close the dialog, and then I'll continue.
02:06I'll also include the name, the blurb, the description, and the price.
02:14For each column that I want to include, I choose the column and click Select.
02:19Now I'm going to include columns from the packages table.
02:23In the Database items list, I'll move back to the packages table, and I'll
02:27choose packageId and packageTitle.
02:32So now in my Select statement, I have the tourId, and a number of other columns
02:37from the tours table, and then columns from the packages table.
02:41Now, I have to describe how the two tables will be joined together.
02:45This is where a little bit of SQL knowledge goes a long way.
02:49I'll go back to the tours table and choose the packageId column, and then click Where.
02:56Then I'll click at the end of the statement, after the Where clause, and type in the Equals operator.
03:03Then I'll go back to the packages table, and choose the packageId column, and
03:08click the Where clause again.
03:10So now I'm saying that I'm selecting all these columns from these two tables
03:15where the packageId from tours matches the packageId from packages.
03:20I'm ready to test my query.
03:22I'll click the Test button, and I should see all of the data coming back,
03:26joined together correctly.
03:28In the first row, I have tourId, the name, the blurb, description, and price, and
03:34then in same row, I have the packageId and the associated packageTitle.
03:40I'll click OK, and then click OK again.
03:44Just as with this simple recordset, all of the finished PHP code is added to my page.
03:50I'll scroll down to where the actual SQL statement is placed, and show you that
03:55it's just like the simple recordset.
03:57It's just an SQL statement.
04:00The more you know about SQL, the more complex and powerful your queries can be.
04:05I'd like to point out one thing that's interesting about this SQL statement.
04:09Notice that the word "description" was placed in quotes, while the other
04:13column names weren't.
04:14That's because Dreamweaver looks at the word "description," and identifies it as
04:18a potential reserved keyword in the SQL language.
04:23It isn't a reserved keyword in all versions of SQL, but just to make sure,
04:28Dreamweaver wraps the name of the column in those quotes.
04:31If you have any similar troubles with column names or other elements of your
04:36database structure where those names collide with reserved words in the SQL
04:40language, you can fix your code in exactly the same way, by wrapping the term
04:45in quotes as needed.
04:47Now I'll test the page, looking at it in Live View, and I won't see any data yet.
04:53But again, that's because I'm not doing anything to display the data on the screen.
04:57I'll show how to do that in a separate video.
Collapse this transcript
Displaying data with repeating regions
00:00Once you've defined a recordset in a PHP page, you can then display the data
00:04in a number of ways.
00:06For this demonstration, I'll use a file named tours.php.
00:10This file already has a recordset defined.
00:14If you look at the file in Code View, you'll see all the PHP code for lines 1 through 39.
00:20You can also go to the Bindings panel and find the recordset there, and
00:25double-click it open it.
00:27This is a simple recordset,
00:29so it's best viewed in that version of the recordset builder.
00:33If you want to make any changes to the recordset, you can do so either from here
00:37or by manually modifying the SQL code in the PHP page.
00:42Now I'm going to preview the page in an external browser, and I'll show you that
00:48right now we're not actually using the data in the page.
00:52The page has all static HTML, including one detailed instance of a tour
00:58package, named Backpac cal.
01:01I'll go back to the page in Dreamweaver and look at the page in Design View.
01:06I'll scroll down to that section,
01:09I'll select the title in the package, and then go back to Code View and show you
01:14that all the information about this tour is hard-coded.
01:18We want to replace this information with repeating data from the
01:22packages recordset.
01:24Here's how I'll do it.
01:26I'll go back to Design View, and I'll start with the title element.
01:31I'll select that value, and then I'll go to the Bindings panel.
01:36I'll open the recordset, and Dreamweaver shows me the three columns that are
01:41being returned in the recordset.
01:42I'll click on the packageTitle, and I'll drag it into the place, dropping it on
01:47top of this selected static text.
01:50That replaces the static text with some PHP code that outputs the packageTitle.
01:57With that text selected, I'll go back to Code View and show you that the PHP
02:02output looks like this:
02:04php echo, then the name of the recordset, and then the name of the column as a string.
02:13I'll do the same thing for the package description.
02:15I'll go to Design View, I'll select the text for the package description,
02:21I'll go to the Bindings panel, and drag the packageDescription column on top
02:26of the selected text.
02:28Then I'll go back to Code View and show you the exact same sort of code here.
02:34You can do the same thing in Code View.
02:35For example, the image source is currently set to a hard-coded image file name,
02:42but we have that information also in the recordset.
02:46I'll select the name of the file, but not the location in which the file is stored.
02:50Then I'll go to the Bindings panel, and I'll drag the packageGraphic column on
02:55top of the selected text.
02:58That replaces the hard-coded graphic file name with the dynamic file name
03:02from the recordset.
03:05I'll do something very similar in the alt value for the current image.
03:09That's also set to the title of the package, so I'll select it,
03:14I'll go to the Bindings panel and drag in the packageTitle on top of the selected text.
03:20Now let's take a look at all of the generated code.
03:24The tour description is using four dynamic values, the packageTitle used twice,
03:30both in the heading 2 and in the alt value for the image.
03:35Then the actual name of the image is being drawn from the database here, and the
03:39description is being drawn from the database right here.
03:42I'll save the changes, and then I'll look at the page in Live View.
03:47I'll update the copy of the file on the testing server when prompted, then look
03:52at Design View, and I'll see the result.
03:55The output looks exactly the same as it did before, but now it's dynamic.
04:00The data is being drawn from the database at runtime.
04:04Right now, I'm only displaying one record.
04:07I'm going to change this now to repeating records, so that I see one instance of
04:12this package information for each row in the recordset.
04:16I'll exit Live View, and then in Design View, I'll locate the
04:22package information.
04:24I'll click anywhere inside the package information, and then in the tag selector,
04:29I'll choose tourDescription, the div tag that wraps all that information.
04:34Now, I'd like to make that div tag repeat, once for each row.
04:39I can do that either from the menu or from the Insert panel.
04:42I've been using the Insert panel a lot, so this time I'll go through the menu.
04:47I'll choose Insert > Data Objects > Repeat Region.
04:53I'll choose the only recordset in this file, rsPackages, and I'll choose All
04:59records, rather than 10 records at a Time, and click OK.
05:03That div tag is now displayed with a visual aid showing the word "Repeat."
05:09That means that we're repeating the div tag once for each row in the
05:12selected recordset.
05:15I'll look at the page in Live View again.
05:18If prompted, I'll say yes, I want to save my changes, and then I'll update the
05:23file on the testing server, scroll down, and show you that now I'm displaying
05:29all the data for the selected table.
05:31There are nine rows in this selected table, and therefore nine instances of the
05:36selected div tag in the repeating region.
05:39So that's how you can dynamically output data from a recordset, using the
05:44Dreamweaver repeating region architecture.
05:47You replace the literal values in your HTML with dynamic values from your
05:51recordset and then define the entire div tag containing the data as a repeating
05:57region, and the HTML is generated at runtime by PHP and MySQL.
Collapse this transcript
Displaying data in a dynamic table
00:00In a previous video, I showed how to display data using a repeating region.
00:06There's another approach, which is to generate a dynamic HTML table.
00:11For this demonstration, I'll use a file named explorerlist.php, which you'll find
00:16in the Explorers folder of the current site.
00:19This file doesn't currently have any record sets, so I'll add one.
00:23It doesn't matter where the cursor is if you're looking at it in Code view, all
00:27of the code for the recordset will always go at the top of the page with a
00:32little bit of PHP code at the end.
00:35With the page open, I'll go to the Bindings panel and click the plus button and
00:39choose Recordset query.
00:42Make sure you're in the simple version of the Recordset builder.
00:45I'll name my new recordset rsExplorers.
00:49The Connection should be set to explorecalifornia, and the Table to explorers.
00:55I'll click the Selected radio button, hold down the Ctrl key on Windows or the
00:59Command key on Mac, and choose explorerId, firstName, lastName, dob and email.
01:07I'll test my recordset and see that it comes back in numeric order by primary
01:12key, but I'd really like it in order by lastName.
01:17So I'll click OK, and then change the Sort to lastName, and I'll test again.
01:23And now it's coming back in lastName alphabetical order.
01:27I'll click OK and click OK to insert the recordset into my page.
01:33Now I'm ready to insert the dynamic table.
01:36I'm still in Code view.
01:37I'll scroll down the page until I find where I want to place the table.
01:42There is an h1 tag set that currently is at line 71 in my version of the file.
01:49I'll place the cursor after the heading1 tags and then add in a paragraph tag
01:54set by pressing Ctrl+Shift+P on Windows or Command+Shift+P on Mac.
01:59The Dynamic Table tool really only works well when you're in Design view, so I'm
02:05going to leave the cursor in that exact location, and then go to Design view and
02:10then I'll insert the dynamic table.
02:12You can do this from the menu by choosing Insert > Data Objects > Dynamic Data > Dynamic Table.
02:20There's also an option in the Insert panel.
02:23I'll use this menu choice, and in the Dynamic Table tool dialog, I'll verify
02:28that the rsExplorers recordset is selected, it's the only one in this page, and
02:33then I'll choose All records. I'll set the Border to 0 and leave the Cell
02:38padding and Cell spacing alone.
02:40These are values that I'll prefer to set later using cascading style sheets,
02:45and then I'll click OK.
02:47The dynamic table is added automatically in the exact location where I had my cursor.
02:53I'll save the changes by pressing Ctrl+S on Windows or Command+S on Mac and
02:58then I'll go up to Live View and copy the file over to the server, and here's the result.
03:04The data is retrieved from the server and displayed in a dynamic HTML table.
03:09I'll do a little bit of editing and formatting.
03:13I'll exit Live View, and first I'm going to delete the column that shows the primary key.
03:19I'll click into the first cell in the column and then drag down to the second.
03:24I'll release the mouse button and press Delete.
03:27I'll change the headings;
03:29by default the heading show the exact column names.
03:33I'd like to show more friendly information, so I'll change the firstName column
03:37header to First Name, lastName to Last Name, dob to Birthdate and for email,
03:46I'll simply capitalize the first character, Email.
03:50I'll also click in the first cell of the row and then drag to the last cell and
03:54release, then in the Properties panel I'll click Header, and that turns those into
04:00TD tags in the HTML.
04:03I'll save the changes, and then go to Live View again, copying the file to the
04:08testing server and I'll see that my dynamic table is now much more friendly
04:13and easy to look at.
Collapse this transcript
Formatting dynamic data
00:00In a previous chapter of the video series, I described how to use the Zend framework,
00:05how to install and configure it in your PHP installation so that you could
00:10take advantage of all of its valuable validation, formatting, and other tools.
00:16I'm now going to show you how to use the Zend framework's zendDate class to
00:21format values that you retrieve from your MySQL Server.
00:24I'll start in Code View.
00:26I'm working in the file explorerlist2.php, in the explorers' folder of the
00:3205_bindingandbehaviors folder, which is currently set as my site foot.
00:37I'll start at the top of the page.
00:39Before I use any class from the Zend framework, I first have to include
00:44the class definition.
00:45So I'll place the cursor at the end of the first PHP code block, and then I'll
00:50press Enter to create a new line.
00:52I'll go to the Insert panel, to the PHP category, and I'll insert a new PHP code block.
01:00Within the code block, I'll use the require_once command.
01:04I'll type in r-e-q, and press Ctrl+Space, and I'll select the
01:08require_once function.
01:10Then I'll pass in the literal string pointing to the name of the file, relative
01:15to the Zend framework library folder, which is already included in my PHP installation.
01:21The relative location of the PHP class definition is Zend/Date.php.
01:28Now, I'm ready to use that class to format my dates.
01:32I'll first locate the data that I want to format.
01:34I'll go to Design View. Then in the dynamic table, I'll click on the dob column.
01:40Then I'll go back to Code View.
01:43That takes me to the value I am interested in formatting.
01:47I'm going to take the value that I'm currently outputting, the dob column of the
01:51row rsExplorers variable,
01:54I'll select that value - not including the semicolon - and then I'll cut it to the clipboard.
02:00Now, I'll place the cursor after the PHP code block that's creating a loop over the data.
02:07I'll create a new line after that code block, then I'll go to the Insert panel
02:11and click once on Code Block to insert the code block.
02:15Within the new code block, I am going to create a new instance of the Zend/Date class.
02:20It will look like this: zendDate = new, and then I'll type in Zend_, and using
02:29code hinting, I'll choose the Zend_Date class.
02:33I'll create an opening parenthesis, and then for the first value that's passed
02:38in, I'll paste, and that pastes in the dob expression that I cut from the
02:44original dynamic table.
02:46I'll type in a closing parenthesis and a semicolon, and then clean up the code a
02:50little bit to make it more readable.
02:53Now, I'm going to move down to the line that currently shows a syntax error.
02:57This is where I removed the value that I wanted to echo, or send to the browser.
03:02And I'm going to replace it with an expression that outputs the date object using
03:07my selected formatting.
03:08It will look like this.
03:11I'll start with a dollar sign, then zendd.
03:15That takes me to my variable zendDate.
03:18I'll press Enter to select it from the code hinting list.
03:21Then I'll type in a dash, greater than, and I'll select the toString function.
03:26Make sure you choose the toString function without the underscore prefixes.
03:31I'll choose the function,
03:33and then for the format, I'll pass in a string that looks like this: an
03:37uppercase M, a slash, a lowercase d, another slash, and two lowercase yys.
03:44I'll type into closing quote and the closing parenthesis.
03:48And now Dreamweaver shows that there are no syntax errors.
03:51So each time through the loop, I'm creating a new instance of the zendData
03:55class, passing in the value from the database, and then within the loop, to
04:00output, I'm using the toString function of the zendDate object and passing in
04:05my preferred formatting string.
04:08Once again, you can look at the documentation for the zendDate class, to find
04:12your own preferred formatting strings.
04:15I'll save and go to Live View, update the file on the testing server, look at it
04:21in Design View, and there are my formatted dates.
04:25You can format the dates any way you like, using the date format values that the
04:30zendDate class supports.
04:32So in this example, I've shown you how to use a bit of hand coding and used the
04:37Zend framework's classes to do the formatting, and combined that with the code
04:41that was generated by Dreamweaver as a dynamic HTML table.
04:45You can now format the table as much as you like, using whatever Cascading Style
04:50Sheet or other formatting tools you know how to use.
Collapse this transcript
Displaying the total number of records
00:00Once you've placed a recordset in a PHP page, it's very simple to display the
00:05total number of records in the recordset in your PHP output.
00:09I'll demonstrate this with the file explorerlist3.php in the explorers
00:14folder of the web site.
00:16I'll place the cursor before the words "Current Explorers," in the heading
00:20above the dynamic table.
00:22And I'll type in the words "There are," and I'll delete the word "Current."
00:26I am going to add a dynamic value, known as a server behavior.
00:32A server behavior is a bit of generated PHP code that in many cases is using
00:37data from a recordset.
00:39I'll go to the Server Behaviors panel.
00:42If you don't have this Server Behaviors panel in your workspace, you can open
00:45it by going to Window > Server Behaviors, or pressing the associated keyboard shortcut.
00:52In the Server Behaviors panel, I'll click the Plus button, and I'll choose
00:56Display Record Count > Display Total Records.
01:00Then I'll click OK.
01:02That adds in a dynamic expression,
01:05the recordset TotalRecords property.
01:08I'll look at the resulting value in Code View.
01:11Here's what it looks like.
01:13We're referring to a variable that's set during the initial declaration of the
01:17recordset, totalRows_rsExplorers.
01:20I'll go to the section of the page that's declaring the recordset, and show you
01:24where that variable is being declared, totalRows_rsExplorers = mysql_num_rows,
01:32and then the recordset is passed in.
01:33I'll save the change and look at the page in Live View, copying it to the server.
01:41I'll look at it in Design View, and there is the result.
01:45There are three Explorers in the database table.
01:48You can place the output of the total number of records anywhere on the PHP page,
01:53as long as it's after the code that retrieves the data from the server and sets
01:58that PHP variable, and Dreamweaver will help you insert the code very easily.
Collapse this transcript
Limiting records with paging controls
00:00The PHP code for paging through a recordset that is displaying a small set of
00:06records and then giving the user links to go page by page is a little bit
00:11complex, but Dreamweaver will help you generate that code very easily.
00:16For this demonstration, I'll use a file named tours2.php, which is in the root
00:21folder of the current site.
00:24This page already has a repeating region that displays the tour packages from the database.
00:31I'll Preview the page in an external browser, copying the file to the server first.
00:36In this version of the page, all nine packages are displayed, which means that
00:41the user has to scroll quite a bit to see everything.
00:44I'm going to add codes so that there only three rows are displayed at a time,
00:49and then links are added that the user can use to move through the content.
00:54I'll close the browser and return to Dreamweaver.
00:57First, I am going to edit the repeating region, so it only displays three rows at a time.
01:03I'll go to the Server Behaviors panel.
01:06Here is the repeating region that I added previously.
01:09It's labeled Repeat Region for the rsPackages recordset.
01:14I'll double-click on the repeat region, and that takes me to the Repeat Region dialog box.
01:20I'll change it to only show three records at a time and click OK.
01:25I'll save my changes and open the page again in an external browser.
01:33Now, I am only seeing the first three rows in the recordset.
01:37The next step is to add hyperlinks that will allow the user to page through the data.
01:42So I'll close the browser and return to Dreamweaver again.
01:45You can place these links on the page anywhere you want.
01:48I am going to place them at the top of the repeat section, after the heading.
01:52I'll place the cursor after the text Something for everyone, and press Enter.
01:57Then I'll go to the Server Behaviors panel again.
02:01I'll click the Plus button, and go to their Recordset Paging section.
02:06You can add four links for Moving To the First Page, the Previous Page, the Next
02:10Page, and the Last Page.
02:13I'll do these one at a time.
02:15I'll choose Move To First Page.
02:16The Link list shows you, Create a new link for the word "First," and then a
02:21number of existing links.
02:23I am going to choose Create a new link for the rsPackages Recordset and click OK.
02:29Then I'll click after the link that's been created and press the Spacebar.
02:33I'll go back to the Server Behaviors panel.
02:36Once again, I'll choose Recordset Paging and this time choose Move To
02:40Previous Page and click OK.
02:43I'll click after those links and press the Spacebar again, go to Server
02:47Behaviors > Recordset Paging > Move To Next Page, and click OK.
02:54I'll click at the end of the links, press the Spacebar one last time, and go
02:58through the process again, selecting Server Behaviors > Recordset Paging > Move
03:04To Last Page, and I'll click OK. This is just text.
03:11You can change the text however you like, or replace the text with your own images.
03:15I'll save the change and go to Live View and click Yes, and Yes, and then in the
03:21page, I see my links.
03:24If you try to clicking these links in Live View, you won't see any reaction.
03:28To really see this work, you must use an external browser.
03:32So I'll exit Live View, and go to the external browser.
03:36I am using Firefox.
03:38I'll make sure I've copied the newest version of the file over to the server,
03:42and now I should be able to page through the data by clicking the Next button.
03:47I'll click Next again, I'll click Previous and Previous again, and I can also
03:52go to Last and First.
03:54So that's how you can add paging to your dynamic display,
03:58displaying a limited number of records and adding links that allow the user to
04:02move forward and back as needed.
Collapse this transcript
Creating conditional regions
00:00Dreamweaver CS5 has server behaviors that let you output code conditionally.
00:06There are six options for conditional code built into Dreamweaver CS5, and you
00:10can learn from the generated code how to write your own conditions.
00:15For this demonstration, I'll use the file tours3.php.
00:19It's in the root folder of my current web site.
00:22In a previous video, I described how to limit the number of records that were
00:26being shown in a particular data set, and then how to add hyperlinks that let
00:31the user page through the data set.
00:34I'll open the file in a browser, first copying it over to the web site, and then
00:39show that I can click through the Next and Previous, but also show you that,
00:44for example, when I'm on the First page, I still see links for First and
00:48Previous, and these links don't do anything.
00:51And if I'm on the Last page, I still see links for Next and Last.
00:56Similarly, I would like to hide those in this condition.
00:59So, I'll close the browser and return to Dreamweaver.
01:04First, I'll deal with the condition for the First and Previous links.
01:09I'll click and drag to select those links.
01:12Then I'll go to the Server Behaviors panel, I'll click the Plus button, and
01:17I'll go to Show Region.
01:18Here are the six available server behaviors for a conditional code.
01:23You can show code if the recordset is empty or not empty, if you're on the first
01:27page or not the first page, or if you're on the last page or not the last page.
01:34I'm going to select Show if Not First Page, and then make sure that I've
01:39selected rsPackages -
01:41it's the only available choice - and click OK.
01:45So now, those links will only display if I'm not on the first page of data.
01:51Now I'll do the same thing for the Next and Last links.
01:54I'll click and drag to select those links, I'll go to Server Behaviors,
02:00I'll click the Plus button and choose Show Region, and I'll select Show if Not
02:06Last Page, and once again,
02:08I'll click OK in the dialog box.
02:11Here's what the generated code looks like.
02:14The hyperlinks have been wrapped in if clauses.
02:19That examines the current page number of the recordset and compares it to the
02:23total number of pages.
02:25So, now I'll test the code in the browser.
02:28I'll go to Firefox, updating the file on the server, and in the initial display,
02:33I see links for Next and Last.
02:36If I click Next, I see all four hyperlinks, because now I'm on the middle page.
02:42And when I click Last, that takes me to the last set of data and hides those
02:46links because they're no longer appropriate.
02:49Now, I'll go Previous.
02:51I'll see all four links.
02:52I'll click Previous again, and now I'll only see the first two links.
02:57So, conditional code is something that's very easy to generate in Dreamweaver.
03:01The code itself is a little bit on the complex side, but by using Dreamweaver
03:06server behaviors, you save yourself an enormous amount of time, and get a very
03:10common behavior that users appreciate.
Collapse this transcript
6. Building Data Entry Forms
Building a simple data entry form
00:00Most dynamic web applications use HTML forms to collect data from the user and
00:06send it to the server.
00:07In this chapter, I'll show you how to build these forms, and how to process the
00:11results with PHP code.
00:13I'll be working with a version of my web site in the exercise files area.
00:17That's in a folder named 06_forms.
00:21I'll go to my site definition, by selecting Site > Manage Sites, and then
00:26clicking Edit to edit the site definition.
00:29Then I'll browse for the local site folder.
00:33I'll go to my exercise files area, and I'll double-click on 06_forms.
00:39I'll select it and save the changes, and then I'll close the Manage Sites dialog.
00:44I'm going to start with a page that's already in this site, named simpleform.php.
00:51It has an HTML table with two labels of First Name and Last Name, and an empty
00:57column to the right.
00:59This is where the data entry form controls are going to be placed.
01:03The first step in creating a data entry form is to create a set of tags named form.
01:09You can do this easily in Dreamweaver through the Insert panel.
01:12I'll place the cursor after the HTML table.
01:15Eventually, the table will be inside the form, but I'll need to move it after
01:20the form is created.
01:22I'll go to the Insert panel, and I'll choose the Forms category.
01:26Then I'll add a form.
01:29Now, I'll go to the HTML table.
01:31I'll click anywhere in the table, then right-click and choose Table > Select Table.
01:37I'll cut the table to the clipboard. Then I'll click inside the form that's
01:42designated by the dashed line, and then I'll paste.
01:47The table is now a part of the form, and any data entry controls that I place
01:52inside the table will be submittable to the server.
01:55Next, I'm going to add some simple form controls.
01:58I'll click into the second column.
02:00Now, if you have any trouble clicking into that column, you can right-click on
02:04the table and choose Table > Expanded Tables mode.
02:08Dreamweaver gives you this mode to make it a little bit easier to click around
02:12in a small table like this.
02:14When you're done with Expanded Tables mode, you can click the exit link at the
02:18top of the editing area.
02:20With the cursor in the second column of the first row, I'll go to the Insert
02:24panel again, and I'm still in the Forms category, and I'll add a text field.
02:30I'll give the text field a value of firstname, all lowercase with no spaces.
02:36I don't need a label, so I'll choose No label tag, and leave the Label entry
02:40blank, and click OK.
02:43That adds the form control where I had my cursor.
02:46Now, I'll repeat the process for the last name.
02:49I'll click into the cell, go to the Insert panel, and choose Text Field again.
02:55I'll give this one an ID of lastname, and once again I don't need a label, and I'll click OK.
03:02Finally, I'll add a button.
03:04I'll place the cursor in the second column, last row.
03:08I'll go to the Insert panel and scroll down toward the bottom, until I find the button.
03:14I'll click once to add the button.
03:17I'll give it an ID of submit, and once again, I'll leave the Label blank, and click OK.
03:23Notice that Dreamweaver sets a value property with the word "Submit" with the
03:28initial character uppercased.
03:30It also sets the Action to something called Submit form.
03:33Now, let's take a look at the resulting code.
03:36Each of the data entry controls is represented by an input tag.
03:40The input tag has both a name and an ID.
03:43The name is used to designate the name of the resulting PHP variable when
03:48the form is submitted.
03:50You can use the ID in JavaScript code in the web browser to address the
03:55control's value and do validation, or other processes.
03:59Finally, the input button, which has an ID and a name of submit and a value of
04:04Submit uppercased, is used to submit the form.
04:08When the user clicks this button, the data in the form is sent to the server.
04:13Notice a couple of other things.
04:15The method is set to post.
04:17There are two commonly used methods for data entry forms.
04:20They're called post and get.
04:23Typically, you set the method to post for a data entry form in PHP, and
04:27the action, when left blank, results in sending the data to the same page that submitted it.
04:33That's exactly what we want to happen, and we're going to leave the value blank.
04:38I'll save the changes, go back to Design mode, and exit Expanded Tables mode.
04:44I'll save my changes by pressing Ctrl+S on Windows, or Command+S on Mac, and
04:49then I'll preview the page in an external browser.
04:52I'm using Firefox, but you can use whatever browser you like.
04:56I'll type Davey Jones and submit.
05:00It takes a moment to submit and process the form the first time, but when it's
05:04re-presented, you'll see that the data entry form is now blank.
05:08That's a visual clue that you're viewing the page for the second time.
05:12Right now, we aren't doing anything with the data that was sent to the server,
05:16but you are seeing the form being submitted and re-presented.
05:19I'll show you how to handle those values being sent from the form with a little
05:23bit of PHP code in the next video.
Collapse this transcript
Handling form submissions with PHP
00:00Once you've created a working data entry form, you can then handle your form
00:04submissions with a little bit of PHP code.
00:08For this demonstration, I'll use the file simpleform2.php.
00:13It has a copy of the form that I created in a previous video.
00:17The first step is to remember what the names of your form controls are.
00:21When I created this form, I created two text controls.
00:25The first one had a name and ID of firstname.
00:28You'll need to remember those values in order to handle your PHP form submission.
00:34To make this easy to code, I'll use the Bindings panel.
00:37The Bindings panel lets you set up form and other types of variables that you
00:42can then easily insert into your PHP code.
00:46I'll go to the Plus button, and I'll choose Form Variable.
00:50I'll set a Form Variable name of firstname, matching the name and ID of the
00:55first form control, and I'll click OK.
00:58Then I'll repeat the process to create a Form Variable for lastname.
01:04By placing these items in the Bindings panel, you're not actually changing the page yet;
01:08you're just creating a bit of reusable code that you can add to your page as you need to.
01:14Next, I'll look at the page in Code View, and I'll go to the top of the page.
01:19The first time the page is viewed, I'm only going to see the data entry form,
01:24but the second time the page is viewed after the form has been submitted, I
01:28want to get the values that the user typed into the form and display them on the screen.
01:33I need a little bit of PHP conditional code to do that.
01:37I'll place the cursor after the body tag, and before the form, and make a
01:41little bit of space.
01:42Then I'll add a PHP code block.
01:44I'll go to the Insert panel to the PHP category, and I'll click on Code Block.
01:50Then I'll make a little bit of extra space inside the code block.
01:55Next, I'm going to ask the question, has the form been submitted?
02:00You can do this by checking for a particular variable, and asking whether it's set yet.
02:05The particular variable I'm interested in is the firstname variable.
02:10Even if the user doesn't type anything into it, it will still create a form
02:14variable when the form is submitted.
02:15I'll use a PHP conditional statement, if, and then I'll put in a pair of
02:21parentheses, and then a pair of braces.
02:26Within the pair of parentheses, I'll use the isset function, and once again a
02:31pair of parentheses.
02:32I'm going to add the reference to the firstname form variable between the parentheses.
02:38Before I do this, I'm going down to the Properties panel, and I'll click
02:42Refresh, or press F5.
02:44This causes Dreamweaver to read the page that I've just hand-coded, and it will
02:48give it the context to correctly add the PHP code I want.
02:53Next, I'll go to the Bindings panel, I'll locate my firstname variable, and I'll
02:58drag it and place it between the parentheses of the isset function.
03:03So, now I'm asking the question, does this variable exist?
03:07And if it does exist, I want to output this and the other variable to the screen.
03:12So, now I'll place the cursor between the curly braces, and I'll use the echo
03:17command a number of times to output some information.
03:20I'll say echo, and then the word "Welcome," comma, space, I'll make sure to end
03:26that statement with a semicolon.
03:28I'll type the word "echo" again.
03:31Once again, I'll refresh before I use the Bindings panel.
03:35I'll go to the Bindings panel and drag in the firstname.
03:38Then I'll put in a dot.
03:40In PHP, that means I'm going to append, or add a value after that.
03:44Then I'll put in a space wrapped in quotes, and another dot.
03:48I'll once again refresh, go to the Bindings panel and drag in the lastname, and
03:54I'll close that statement with a semicolon.
03:57Finally, I'll add one more echo command, and explicitly add a break tag, or br
04:03tag, to cause a line feed at the end of this line.
04:07So now, I'm handling and outputting the values that are submitted from the form,
04:12but I'm only doing this if the form was submitted already and this is the
04:15second time I'm viewing the page.
04:18I'll save my changes, and I'll test the page in an external browser.
04:26When the form opens, I'll click into the first control, and I'll type Davey Jones.
04:33I'll click Submit, and when the form is submitted, I see the response,
04:37Welcome, Davey Jones.
04:39This response is created by the echo commands within the conditional code that's
04:44placed above the form.
04:45So, that's a look at the basics of how data entry forms work, and how you
04:49process them with PHP code.
04:52If your form was set up with a method of post, your variables will appear like this:
04:57dollar underscore POST, bracket, then the name of the form control, wrapped in
05:02quotes, close bracket.
05:04And you can check to see whether the variable exists at any point by wrapping it
05:08in the PHP isset function.
Collapse this transcript
Creating a customer email form
00:00You can apply your knowledge of HTML forms and PHP to very common web tasks,
00:06such as collecting information from a user, and sending an email from your PHP code.
00:12In the remaining videos of this chapter, I'll show you how to do this task, using
00:16a data entry form with a variety of input controls.
00:20I'm working with the file join.php which is under the Explorers folder in the
00:25web site root for this chapter.
00:28This file already has a data entry form.
00:31The form was created as part of a previous video series named Dreamweaver
00:35CS5 Essential Training.
00:37You can learn more about the structure of this form in that course.
00:41One particular thing I want to point out about this form is that it uses a
00:45particular kind of element called a legend, and when you look at this particular
00:49form in Dreamweaver CS5, it looks like the legend overlaps some of the data entry controls.
00:56You can verify that this won't happen when you actually run the page in the browser.
01:00I'll use the feature called Inspect. I'll click the Inspect button and I'll copy
01:06the file over to the testing server and then I look at the file in Split View.
01:11I'll scroll down to the data entry form and I'll click on the legend element,
01:16and Dreamweaver matches up the element seen in Live View on the right with the
01:21code, seen in Code View on the left.
01:23I can also run the same file in the external browser, and show you that the form
01:30looks fine when you see it there.
01:33This data entry form has three different sections, but they're all part of
01:37the same HTML form.
01:39There is a first name, last name, email, address, and so on.
01:43There's login information and profile information at the bottom, and the Join button.
01:49When you click the Join button, it triggers some validation tools that are already built into the form.
01:55The password and confirm password elements use validation tools that are a part
02:00of this Spry/Ajax Framework.
02:02Spry is a set of JavaScript and CSS files that are delivered by Dreamweaver CS5
02:09and are included in this form.
02:11In this particular form, the password and confirm password elements are required
02:16and they must match.
02:17I'll type in some values, and I'll make sure that they match, and you'll see
02:24that the validation messages appear and disappear as I type, then I'll scroll
02:28down and click the Join button and you'll see that that simply reloads the form.
02:34Our job in the remaining videos is to add some more validation tools to the form
02:40to capture all of the data being sent in by the form, not just the text fields,
02:45but also these check box elements and radio buttons, and then finally, to
02:50process the data entry and create an email that you can send from the server.
02:56Along the way I'll work in copies of this file, this one is called join.php.
03:01In the next exercise I'll use join2.php, in the next one join3.php, and so on.
Collapse this transcript
Validating form controls with Spry
00:00Dreamweaver CS5 makes it very easy to add client-side validation to your data
00:05entry forms using validation controls that are part of the Spry framework.
00:11This isn't a new feature;
00:12Dreamweaver CS4 had it as well, but the number of available controls for
00:16validation has expanded in Dreamweaver CS5.
00:18I will show you how to add one of these controls and configure it.
00:22The data entry form that's already been created in the site has some validation
00:28tools but not everything we need.
00:30Let's take a look at the database structure that matches this data entry form.
00:34I will go to the Databases panel, to the Explore California database connection,
00:40and then to the Tables list.
00:42Here is the table that matches the data entry form, and eventually we will
00:45receive data from it.
00:48The data entry form has controls that match the columns in this table.
00:53So there is a text field for the firstName and a matching firstName column, a
00:57text field for the lastName and a matching lastName column, and so on.
01:02Notice that many of these columns are marked in the database as required:
01:06the firstName, the lastName, the e-mail, and so on.
01:09I am going to modify the form to make sure that the user enters values that are
01:14expected by the database.
01:17I won't do this for the entire form in this exercise.
01:19I will just do a couple of the controls.
01:22You'll have enough information to complete the task on your own.
01:25I am going to apply a required validation rule to these three controls, for the
01:31First Name, Last Name, and Email Address.
01:34I will start with the First Name.
01:36I will click on the Control, then I will go to the Insert panel, to the Spry category.
01:44In Dreamweaver CS5, there are many validation tools available, including one
01:50for a TextField, for Textarea, Checkbox, Select, Password, Password Confirm and Radio Group.
01:58I'm going to apply the Spry Validation TextField.
02:02I'll click once, and that adds the code around the text field that's needed.
02:08Now let's take a look at the Spry text field properties.
02:10I will go to the Properties panel.
02:13You can leave the name of the text field alone.
02:15I will match it to my control.
02:17I will call it spryfirstname.
02:21The Type list includes many different data types that you can look for.
02:25I don't need any particular data type here, so I'll leave that set to None.
02:31If you know how to use regular expressions - a way of creating string formats -
02:36you can choose Custom, and then you'll be able to enter a pattern.
02:40You can also add a minimum number of characters and a maximum number of characters.
02:44For example, in the database, the First Name text column allows up to 50 characters.
02:51So I can match that in my Spry validation.
02:55When I select the maximum number of characters, the Preview states switches to
02:59something called Exceeded Max Number ofCharacters and at this point, I can
03:03change the error message that would display.
03:05I am going to switch the Preview state back to valid, and show you that there's
03:10a bit of text on the form already that we aren't going to need.
03:15I'll click into the Required element, and delete it, and I'll do the same thing
03:20for the versions next to Last Name and Email.
03:26Then I'll go back to the Spry text field for spryfirstname, and I'm going to
03:30indicate when I want to validate.
03:33By default, validation happens on submit, meaning when the user clicks the
03:38button for the form.
03:39You can also cause validation to happen on Blur, which means when the user
03:44clicks or tabs out of the control, and on Change, which means when the user types.
03:50Validating on Change is overly aggressive for my money, so I will uncheck that
03:55option, and we'll only validate on Blur and on Submit.
04:00Now I'll follow the same steps for the Last Name control.
04:03I will click the Control, go to the Insert panel and choose Spry
04:09Validation TextField.
04:11I'll click into the Properties panel, into the name of the control, and
04:15change it to sprylastname.
04:17I will once again set the maximum characters at 50, I will change the Preview
04:24state back to Valid, I will add the Validate on Blur, and once again, I am
04:30leaving Required checked.
04:32Now, let's do the Email.
04:33I will click the Control.
04:36I'll add the Spry Validation TextField.
04:40This time, I'll set the Type to Email Address.
04:44Notice that the Preview state switches to Invalid Format.
04:47I am going to change that string by clicking into the preview state and changing
04:53that text to Expecting e-mail format.
04:56Then I will click back on the text field.
05:00I will add Validate on Blur, and the Maximum characters set to 50.
05:07Finally, I'll change the name of the Spry TextField to Spryemail.
05:13So now I've added validation to these three controls:
05:16First Name, Last Name, and Email.
05:19I'll save my changes, and I'll be told by Dreamweaver that two new files are
05:24being added to my web site, named SpryValidationTextField.css and
05:29SpryValidationTextField.js.
05:32These files are used by Dreamweaver at runtime in the browser to cause the
05:37validation to happen.
05:39When you deploy your site to your production server, you need to make sure that
05:43these files are included.
05:44I will click OK, and then I'll test the page in an external browser.
05:49I'll make sure that I am copying everything over to my testing server, and then
05:58I'll scroll down to the bottom and click the Join button, and show that the
06:02three validation errors are being displayed.
06:05I'll click into the First Name, and type "Joey," and the Last Name Smith, and
06:10notice that as I tab, the validation errors are being cleared.
06:14That's because I added the Blur option for when I wanted to do the validation.
06:19Now, I'll type in an e-mail address, but I'll type it in incorrectly.
06:26I see the message, Expecting email format, and that's because I am missing the
06:30dot, and the characters at the end that exist in every e-mail address.
06:35So I'll click into the e-mail address again, and add the .com.
06:39I'll tab again, and now the field is valid.
06:43I'll also go down to my Password and Confirm Password elements and type some
06:47values in that will be valid.
06:51And then, if I were actually submitting data to the server, I'd be ready to
06:55click the Join button.
06:57So that's a look at how to add some additional validation to your data entry
07:01form using Spry Validation components.
07:05The Spry Library is available for free from Adobe on opensource.adobe.com, but
07:12it's also included with Dreamweaver CS5, and you've seen how Dreamweaver CS5
07:17generates most of the code you need for you.
07:20It's worth looking at the code that's generated by Dreamweaver to implement
07:24these features of the Spry Framework.
07:26The Spry framework can be downloaded for free from Adobe's web site.
07:30Go to www.adobe.com/go/spry.
07:38This will take you to the latest version of the Spry framework.
07:42You can download this for free, take a look at the documentation, and use all of
07:47the elements of the Spry framework, even those elements that aren't
07:50automatically implemented by Dreamweaver CS5.
Collapse this transcript
Populating a list control with dynamic data
00:00In data entry forms that collect personal information,
00:04it's very common to present a list of available states or other
00:08geographical regions.
00:10In a static HTML page, these sorts of lists have options that are filled in manually.
00:15For example, in this file, join3.php, there's a pulldown list, or a select control.
00:23The options in this control are listed manually.
00:26If you select the control in Dreamweaver and then go down to the Properties
00:30panel, then click the List Values button,
00:33you'll see the list of items that have been manually added to the list.
00:37In many situations though, it's a good thing to populate these sorts of lists
00:42from a database on the server.
00:43I'll show you how to fill this sort of controlling with dynamic data from a database table.
00:49First, you'll need to make sure that your database connection is set up correctly.
00:54Go to the Databases panel, to the explorecalifornia database connection, and
00:59double-click it to open the MySQL connection dialog.
01:02The files that are included with this course have been configured for
01:06Windows and WAMP server.
01:09The password is set to a blank string.
01:11If you're working on Mac with MAMP, type in a password of root, r-o-o-t.
01:17Then, either way, click the Test button.
01:21If you get this dialog, indicating you haven't specified a password, click OK,
01:25and click Test again.
01:28Then regardless of whether you're working on Mac or Windows, you should see the
01:32message that the connection was made successfully.
01:35Click OK, and click OK.
01:39Open the explorecalifornia database connection, and open its Tables list, and from
01:44there, go to the states table.
01:46You'll see that the states table has two columns: stateId and stateName.
01:51These match the values that are going to be used in the pulldown list.
01:55Right-click on the table and choose View Data, and you'll see that the table is
02:00populated with all the data you need for the list.
02:04Click OK to close the panel. Click on the List Values button again and click
02:10the minus button a whole bunch of times.
02:16You're going to remove all of the static data in the dynamic list, and then click OK.
02:23The next step will be to add a recordset to this page that retrieves the state's
02:28data from the states table on the database.
02:32Go to the Bindings panel, click the Plus button and choose Recordset (Query).
02:38Name your new recordset rsStates.
02:42Change the table to states. Leave the column is set to All.
02:47Notice that you'll be retrieving the data for both the stateId and the stateName
02:51column. And set the Sort parameter to the stateName.
02:56Click Test and you should see the data returned in alphabetical order, by stateName.
03:03Click OK, and click OK again.
03:07Now your recordset is a part of the page.
03:09Peak at Code view, and you'll see that the code for implementing the recordset
03:14is at the top of the page, including some boilerplate PHP code, and the actual
03:20SQL statement that retrieves the data from the server.
03:24Go back to Design View and once again click on the pulldown list which now
03:29shows that it's empty. Click Dynamic.
03:32You'll add data from the recordset.
03:34Under Options from Recordset, select rsStates.
03:38Set the values to stateId, and the labels to stateName.
03:43You can also, if you like, add a static option. The static option would be an item
03:48such as choose a state. For this example, we'll leave that blank.
03:54Click OK, save your changes, and then test the page in an external browser.
04:00When the page opens, the data is retrieved from the server and the pulldown list
04:07is populated with the dynamic data.
04:09Let's take a look at the generated code for the select control.
04:13Close the browser, and in Dreamweaver go to Code View, and you'll see that the
04:18select control now loops over the recordset, and creates one option element for
04:24each item in the recordset.
04:27Here's the actual option element, and all the rest of this code is executing
04:31the loop over the recordset so that you get one item in the recordset for each
04:36item in the database.
04:38So that's a look at how to retrieve data from the database server and
04:42implement a dynamic pulldown list or list control without having to do any
04:47hand coding on your own.
Collapse this transcript
Working with multiple checkbox controls
00:00One of the most complex skills you need to learn to work with data entry forms
00:05is how to deal with multiple choice questions in a form that are represented by
00:09multiple check box controls.
00:12A single check box control is dealt with as a yes or no question.
00:17If the check box is selected, that means the user has selected the option, and if
00:21it's deselected, that means no.
00:23But with multiple check box selections to a single question, one very common way
00:28of dealing with it is to give all the check boxes the same name, and then to
00:32handle the results on the server using a little bit of PHP code.
00:36I'll demonstrate how to do this with a version of my data entry form called
00:40join4.php, in the explorers folder.
00:44The first step is to make sure that all of your check boxes are named the same,
00:48and that they have a little bit of extra notation at the end of the name that
00:52turns them from a simple variable into something called an array.
00:56An array is an ordered collection of data. For example, this check box
01:01with a value of Backpack Cal has a name of interested, and if I look at the
01:06properties for the other check boxes in this set, you'll see they all have this same name.
01:11In order to deal with them in PHP, change the name of the check box and add a
01:17beginning and ending bracket -
01:20that's the square bracket character, not the curly brace - and do the same thing
01:24for each of these check boxes.
01:27I'll click on each one in turn and type in the beginning and ending bracket, and
01:31then I'll be ready to do a little bit of hand coding in PHP.
01:36The actual processing of the PHP code is not something that Dreamweaver
01:40will help you with.
01:42It's one of those circumstances where you just have to code it yourself.
01:46I have nine check boxes,
01:48they all have the same name, and they all have the beginning and ending brackets
01:51at the end of the name, indicating that they will be an array of values.
01:56Also notice that each of the check boxes has a unique, checked value.
01:59Let's take a look at how that is reflected in the actual HTML code.
02:04I'll go to Code View and show you that each of the check boxes is an input control.
02:09It has the name that I've assigned of interested with the array notation.
02:14The type is check box. The ID is the same as the name right now, but that's
02:19something you might want to change later.
02:21Then the value for each of the check boxes is unique.
02:26Now when the user submits the form, we're going to be submitting the form back to itself.
02:33To make that happen, I've set the Action attribute using a PHP expression of
02:38_server PHP_self.
02:41That means the current page as it's seen by the browser.
02:45So now go to the top of the code.
02:47Whenever you place code in a PHP page that already has a database connection
02:51include, place the custom PHP code after that.
02:56That will ensure that Dreamweaver can still find the connection for further
02:59work with databases.
03:01After the require_once command for the database connection, I'll create a new PHP code block.
03:08Then within the code block, the first question I'll ask is, has the form been submitted?
03:14The button in the form has a name of Submit, and that's going to create a new
03:18post variable named submit when the form is submitted.
03:21So I'm going to use a PHP function called isset.
03:24I'll type the first few characters of the function, iss, and press Ctrl+Space,
03:32and there's my function, isset.
03:35Does the submit variable in the post-array exist?
03:39That code will look like this, $_POST, with post in all uppercase, then
03:46bracket, quote, submit, close quote, close bracket, close paren and close paren.
03:55So, if this condition is true, that means the form has been submitted.
04:00I'll add a pair of curly braces where I can place code that I want it to execute
04:04only in that condition.
04:06Now, I'll ask the question, has the user checked any of the check boxes?
04:11Once again, I'll use the isset function.
04:14If the user checks at least one check box, there will be a post variable with
04:19the name of the check box, and it will be an array.
04:22If they haven't checked any of the check boxes, than that variable won't exist at all.
04:27So, once again, I'll use an if command, and I'll call the isset function, and
04:33this time, I'll look for the variable 'interested.'
04:37Notice in this circumstance, I don't put in the opening and closing bracket.
04:42I only put that into the HTML code.
04:45When the user selects one or more items though, this variable will show up as an array.
04:52Once again, I'll add a pair of braces, and I'll also add an else section for
04:57the alternative state.
04:58I need to make sure that I've added the extra parenthesis at the end of the line
05:02there, and that'll fix my syntax error.
05:05In the condition where the user has checked at least one of the check boxes,
05:08I'm going to transform the array - which is complex object - into a comma delimited string.
05:15For that, I'll use the PHP implode function.
05:19It looks like this.
05:20I'm going to create a variable called strInterested.
05:23It'll be a string values,
05:25so I'm prefixing it with str, and I'm going to get this value using the implode
05:30function, which looks like this.
05:32You pass two values into implode.
05:35The first value, or argument, is called the glue.
05:38It's a character, or set of characters, that's going to separate the values in the
05:42array from each other. I'll type in ",".
05:47You can use either single or double quotes in this circumstance, and then I'll
05:52pass in, as the second argument, $_POST, bracket, quote, interested.
06:00This transforms the complex array into a string that has commas between the
06:06values in the array.
06:08In the circumstance where the user hasn't selected any of the check boxes, I'll
06:13explicitly set strInterested to a blank string.
06:17So now, no matter what the user does with those check boxes, the strInterested
06:22variable will exist.
06:23I'm just going to add a little bit of debugging code.
06:27After the conditional clause, I'll use the echo command.
06:32I'll start with a literal string of "interested in," and then I'll append to
06:37that strInterested.
06:40The dot is used to append one value to another.
06:43Then because I'm only debugging at this point - I'm not actually doing
06:46anything with the values -
06:48I'll call the PHP exit function, which terminates the processing of the
06:53current page and will simply output to the browser whatever I've echoed in this function.
06:58Now I'm ready to test my form.
07:00I'll save my changes and preview the page in an external browser, making sure
07:06that I copy the file over to my server directory.
07:08I have to fill in some minimal information in this form to satisfy its
07:13client-side validation rules,
07:15so I'll type into the first name Joey, last name will be Smith. The e-mail
07:20will be joey@abc.com.
07:23I also need to fill in password information, because I have validation rules there.
07:30Then I'll go down to the Tool Profile section, and I'll select some random check boxes.
07:37I'll click the Join! button, and there's the result,
07:40a comma delimited list of the values that the user has selected.
07:45So that's how you prepare a form with multiple check boxes and then handle their
07:49selections on the server, using a little bit of custom PHP code.
07:54This is an example of a circumstance where Dreamweaver can't actually
07:58generate the code for you, and so understanding how to create the code in PHP
08:02is an invaluable skill.
Collapse this transcript
Sending email with Zend_Mail
00:00Once you've prepared your data entry form, and have captured all of the
00:04information you need from the HTML form, you're ready to send e-mail.
00:08There are number of ways to do this, but my favorite approach is to use classes
00:12in the Zend framework
00:14that make it easy to work with a variety of e-mail servers.
00:18The first step, working in Dreamweaver, is to add information about the
00:21appropriate Zend classes to site-specific code hinting.
00:26That will make it a lot easier to create the required PHP code.
00:30Now, this exercise is dependent on your having set up the Zend framework, and
00:34configured it in your PHP server, which I showed how to do in a previous
00:39video in this series.
00:41I'll go to the menu and choose Site > Site-Specific Code Hints.
00:45I'll work with my existing Zend framework structure.
00:48Right now, I've only included the date classes in my structure.
00:52I'm going to add the e-mail classes.
00:54I'll click the Plus button. Then I'll browse.
00:59I'll drill down to Zend, and I'll choose the Mail folder.
01:04The Mail folder contains everything I need:
01:06both the Zend Mail classes, and other dependent classes. I'll click Select.
01:11I'll check the Recursive option, so I make sure I include everything in that
01:16directory and its subdirectories.
01:18I'll add the .php extension to the structure.
01:22Then I'll click Add.
01:23Then I'll click OK.
01:25Click OK again, and click Save.
01:29Now I'll get code hinting for my Zend mail classes.
01:33Next, I need to include the required class files.
01:36I'll place the cursor after the require_ once command for explorecalifornia.php.
01:42That's my database connection definition.
01:45And I'll add a new PHP code block by going to the Insert panel, to PHP, and I'll
01:52click once on Code Block.
01:54I'm working with an SMTP server.
01:57Your specific requirements may differ, and you need to know something about your
02:01server in order to send mail correctly.
02:04My SMTP server requires authentication.
02:07So I'm going to need to include two classes.
02:11I'll put in a require_once command for the first one, and this will be a class
02:15called Zend/Mail.php.
02:19Then I'll add a second require_ once command, and this will refer to
02:24Zend/Mail/Transport/Smtp.php.
02:31Those two PHP files together will contain everything I need to send mail.
02:37Now I'll go down to the conditional code, where I'm handling my form submission.
02:42I'll place the cursor after the conditional block and before the echo command.
02:46I'll make some empty space.
02:48Then I'll press F4 to expand to fullscreen coding.
02:52Again, I'm working with a particular SMTP server,
02:55so I need to provide a bunch of information.
02:58I'll set up my configuration as an associative array using this code.
03:02First, I'll create a variable named config.
03:05I'll create it as an array, with named values.
03:08The first named value is auth, which I'll set as the value 'login.'
03:14Notice that I'm using equals, greater than as the separator between the key
03:19name and the key value.
03:21Next, I'll set a value named port.
03:23Your particular SMTP server may be different than mine.
03:27The default is 25, but my ISP, or Internet Service Provider, requires a value of 8889.
03:35Check with your ISP for the details.
03:38Next, I'll enter my username.
03:42I'll set that to my e-mail address. And finally my password, which I'll set
03:51to my e-mail password.
03:55So that configuration array contains authentication information.
04:00Once again, check with your ISP, or your SMTP server documentation for the
04:05detailed information you might need.
04:08Next, I'm going to create an instance of a class named Zend_Mail_Transport_Smtp.
04:14The definition for this class is in the Smtp.php file that I already included
04:19with the require_once command.
04:22I'll create a variable named transport.
04:25I'll create it as an instance of the Zend_Mail_Transport_Smtp class.
04:30I'll type in smtp, and show you that I get a list of all classes that have that
04:35string in their names.
04:37I'll choose the last one that shows up, Zend_Mail_Transport_Smtp,
04:42then the DNS name of my e-mail server.
04:48Then I'll pass in my configuration array.
04:53Then I'll close the call to the constructor function of that class.
04:57I'm ready to start sending some mail.
04:59The next step is to create a variable that is an instance of the Zend_Mail class.
05:05The code will look like this.
05:06I'll name my variable mail.
05:08I'll create it as an instance of new Zend_Mail.
05:13When you create this object, you don't pass in any values.
05:17Next, I'm going to use a set of methods or functions that create various
05:22parts of the e-mail.
05:24First, I'll call a function which I'll call by typing dash, greater than, and here is a listing
05:30of all the different functions that are part of the Zend_Mail class.
05:34The first one I'll call will be setBodyText, and I'll pass in the following value:
05:41"You are interested in," and then I'll add a dot, and the variable strInterested
05:48that I already created.
05:49I'll close the function with the closing parenthesis and a semicolon.
05:54Next, I'll call the function setFrom.
06:00I'll type in my e-mail address and my name.
06:03Next, I'll call a function called addTo.
06:06This allows me to add an e-mail address that I want to send the e-mail to, and I
06:10can call it as many times as I want.
06:13The first value I'll pass in is the actual e-mail address, which I'll get from
06:18the data entry form, using the syntax $_POST, then 'email.'
06:25The second value will be the user's full name, which I'll get from $_POST, then
06:31bracket, 'firstname,' close bracket, then a dot, then a space wrapped in quotes, then another dot, then
06:42$_POST open bracket, and then in quotes 'lastname' close quote, close bracket, close parenthesis, semicolon.
06:54So now I've indicated where the e-mail is going to be sent.
06:58Next, I'll set the subject.
07:00I'll call a function called setSubject.
07:04I'll pass in a literal string of 'Welcome to Explore California.'
07:11Now I'm ready to send my e-mail.
07:14I'll call the mail object send method, and I'll pass in my transport object,
07:20which is the variable, transport.
07:23So that's all the code.
07:24Now let's give it a try.
07:26I'll save my changes, and I'll run the page in the browser, making sure I copy
07:31it over to the server.
07:34In the form, I'll type in my name.
07:36I'll type in my e-mail address.
07:43I'll fill in other values that are required by the form.
07:47Then I'll select some tours.
07:50I'll click the Join button, and I should get the output that I saw before.
07:55In a complete implementation, I would continue processing the form, and display
08:00a message instead of the form, saying that the e-mail had been sent.
08:04So that's a look at how to use the Zend framework's e-mail capabilities.
08:08They're much more complete than what's included in the core PHP libraries.
08:13You can use SMTP server authentication.
08:16You can build complex functionality in your PHP pages to build either text-based
08:21e-mail, such as I've done here, or complex, HTML-based e-mails.
08:26Check the documentation for the Zend_ Mail class, and its related classes, which
08:30allow you to send e-mail through a variety of e-mail servers.
Collapse this transcript
7. Managing Server-Side Data
Using data wizards
00:00Dreamweaver supports a variety of features that help you generate PHP code for
00:05retrieving, inserting, updating, and deleting data in a MySQL database.
00:11In all of the videos of this chapter, I'll work in a folder of the exercise
00:15files area named 07_managingdata.
00:18If you're working with the exercise files, set your site definition to point to
00:23this as the root folder.
00:25I'm going to start by showing you how to use one of the data wizards that's
00:29included with Dreamweaver CS5.
00:31These wizards are very easy to use and work very quickly, but they may not
00:36always be modifiable for your own site.
00:39First, I'm going to check to make sure that my database connection is set up correctly.
00:44I'll open any PHP file.
00:46I'll select index.php from the Home folder.
00:49Then I'll go to the Databases panel, and I'll double-click explorecalifornia.
00:54If you're working on Windows with WampServer, the settings should already be correct.
00:59If you're working with MAMP on Mac OS X, click into the Password entry and
01:04type "root," and then regardless of which operating system you're working on, click Test.
01:10If you're working on Windows, you might see this message.
01:14If so, click OK, and then click Test again.
01:18And then regardless of whether you're working on Mac or Windows, you should see
01:21the message that the connection was made successfully.
01:24Click OK and click OK again.
01:27Now you're ready to create a web page using one of the data wizards.
01:32Create a new page based on the page type PHP.
01:37Set the Layout to none and click Create, and then save the file into your site's
01:42Home folder, and name it insertfromwizard.php, and click Save.
01:49Then look at the page in Design View.
01:52I'm going to add a data entry form that primarily uses text boxes, but has
01:57one pulldown list, or select control, that uses data from the states table of my database.
02:03So before using the wizard, I'll add a recordset for that table.
02:08I'll go to the Bindings panel and click Plus and select Recordset.
02:13If you see the advanced Recordset dialog appear, click the Simple button, and
02:17you should see this display.
02:19Give the new recordset a name of rsStates.
02:23The Connection should be set to explorecalifornia, and then set the Table to states.
02:29You'll be selecting both columns of the states Table:
02:31stateId and stateName.
02:33Set the Sort value to stateName, click Test, and it should show you a list of
02:40the first 25 records from the states table.
02:43Click OK and click OK again.
02:47Now you're ready to use a wizard to add a data entry form.
02:51Go to the menu and choose Insert, choose Data Objects, and you'll see three
02:57items named Insert Record, Update Record, and Delete Record.
03:02Choose Insert Record and then Record Insertion Form Wizard.
03:07Once again, you're asked which table you want to work with. Choose explorers.
03:12Next you're asked which page you want to navigate to after the data entry form is finished.
03:18Click the Browse button, and make sure that you're in the correct folder,
03:24starting from 07_managingdata.
03:28From there, go down to the explorers folder and choose explorerlist.php.
03:34You'll see that Dreamweaver sets that up as a relative address.
03:39Because your form file is in the root folder, you'll be navigating to
03:42explorerlist.php in the explorers folder.
03:46Now you're asked which form fields you want to display.
03:50You don't want to show the primary key column.
03:52MySQL will add the value for that.
03:55So click explorerId and then click minus, and that removes that column from
04:00the data entry form.
04:01Next, scroll down a bit and click on the state column.
04:05Display that as a menu, rather than a text field.
04:09Then click Menu Properties.
04:12I'm going to display the values from the database query, the recordset that I
04:15already added to this page.
04:17So I'll choose From database, and I'll see the recordset rsStates appear,
04:22it's the only recordset in this page, and I'll indicate that I want to get the
04:26labels from the stateName column, and I'll click OK, and that takes me back to
04:31the Record Insertion Form Wizard, and I'll click OK again.
04:35There is my data entry form.
04:37I'm going to test the form.
04:39I'll save the file and then view it in a browser.
04:43If you see the dialogs asking whether you want to copy the files to the server,
04:47indicate that you do.
04:49Once the form opens, make sure you type values into every text field.
04:54I'll set the FirstName as Joey, the LastName as Adams.
05:00Make sure that you enter a valid date for the Dob, or date of birth.
05:04I'll enter a value of 2007.
05:07You can add any e-mail address, and then any address value, and any city.
05:14Set the Zipcode, UserName, and Password to any values you want.
05:21Then click Insert record.
05:23After the data entry form functionality is complete, you'll see that the new
05:28data is listed in the explorerlist page, but you might notice an issue, that the
05:33Birthdate is displayed in an odd way.
05:36I entered a valid date, but it's being displayed as a value of 11/30/99.
05:41To investigate that, I'll go to phpMyAdmin and look directly at the database contents.
05:48I'll go to the explorecalifornia database, to the explorers table, and I'll show
05:52you that all the values that I entered into the form are in the database, but
05:57that the Dob was entered incorrectly.
06:00One of the challenges with using Dreamweaver's automatic PHP code-generation is
06:04that it isn't entirely up to date with the requirements of the MySQL database.
06:09So in the next video, I'm going to show you how to correct this issue by
06:13writing a little bit of custom PHP code and customizing the code that's
06:18generated by Dreamweaver.
Collapse this transcript
Formatting dates for SQL
00:00In a previous video, I described how to use the Record Insertion Wizard to
00:05create a data entry form that would collect information from the user and add
00:09it to the MySQL database, but I showed that there is a challenge with working with dates.
00:15That's because the code that's created by Dreamweaver doesn't do an adequate job
00:19of formatting dates as they're expected by MySQL.
00:23I'm working in the file, insertfromwizard2.php, in the root folder of the current site.
00:30Here is the problem code.
00:32It starts with a case statement, and it's within a function
00:35named GetSQLValueString.
00:38The case statement for dates assumes that the user has typed in a value in a
00:43format that's acceptable to MySQL.
00:46Clearly, that isn't always the case.
00:48So I'm going to replace this string with a little bit more complex PHP code
00:53that uses the Zend_Date class that I've demonstrated in previous videos.
00:58I'll go to the top of the file and add a require_once command to incorporate the
01:04Zend_Date class into my page.
01:07I'll add a PHP code block and then the require_once command and then
01:12the Zend/Date.php file.
01:15Make sure you complete the PHP code block at this point.
01:20Then go down to the offending code.
01:22Here is the line of code I need to replace.
01:25I'm going to select and delete it, and then I'll replace it with a complete if else statement.
01:31I'll start by creating the entire conditional logic, with if and a pair of
01:36parentheses, and a pair of braces, and then an else, and another pair of braces.
01:44Then I'll go back to the parentheses after the if and add the condition I'm examining.
01:49I'm asking the question, did the user type in a value at all?
01:53I'll enter $theValue and then the equality operator, double equals, and then
02:00quote, quote, meaning blank string,
02:02Dreamweaver's syntax checking now shows me that there are no syntax errors.
02:07I now have a complete conditional block.
02:10If the value that the user typed in is blank, I'm going to set it to a value of
02:14null, using a very simple assignment statement of theValue =, and then the word
02:19"NULL" in uppercase.
02:22In the else clause, I'm going to assume that the user typed in a value formatted
02:26as a date, in the format month/day/year, and eventually I'll add validation rules
02:33into my data entry form that ensures the value is typed in in this format.
02:38I'll take the value the user typed in and turn it into an instance of
02:42the Zend_Date class.
02:44I'll create a variable called zendDate, and I'll create it from a new instance
02:48of the Zend_Date class, and the first value that I'll pass in is the value that
02:53the user typed in in the form, theValue.
02:56The second part is the format that I'm expecting.
03:00I'll type that in as a literal string, using quote, an uppercase M for the
03:06Month, then a slash, then a lowercase d for the date as a number, then a slash,
03:12and then four ys for the year.
03:15I now have an instance of the Zend_Date class, representing the value the user typed in.
03:20I can format it any way I want.
03:23I'll create a new line of code, and I'll replace the variable of theValue using
03:28a single quote, a formatted date, and another single quote.
03:32I'll start with a single quote wrapped in double quotes, then a period,
03:36indicating that I'm going to concatenate, or append another value.
03:40Then I'll call the zendDate objects to string method.
03:45I'll pass in a formatting string, indicating the formatting that's expected by MySQL.
03:51In double quotes, it will look like this: yyyy for a four-digit year, then a
03:57dash, then MM in uppercase, then a dash, then dd in lowercase for the day, and
04:04finally, I'll concatenate another single quote at the end.
04:08So now I have a formatted date string wrapped in single quotes.
04:12That's the extent of the changes to my data entry form's code.
04:16I'll save my changes and then run the form in the browser.
04:21I'll type in some values.
04:23The FirstName will be Mikey, then Jones.
04:26Make sure that you type in a valid date of birth in the common format used
04:30in the United States.
04:32I'll type in a value of 5/12/1963, type in any e-mail address, and then type in
04:42any other values you like in the rest of the form.
04:45Because of certain restrictions in the database structure, you must type in
04:49values into all of these form controls.
04:54Once you've typed in all of the values, click Insert record.
04:57You should go directly to the explorerlist page and see that this time the date
05:02was entered correctly.
05:04Here is my new record, and the date is displayed, formatted by the Zend_Date class.
05:09So that's a look at how to customize your data entry forms after Dreamweaver
05:14has generated the code.
05:15This strategy can be used both for code that's generated by the Record Insertion
05:19Wizard and for code that's added to existing forms, which I'll show you how to
05:24build in another video.
Collapse this transcript
Creating a custom data entry form
00:00In previous videos, I described how to use the Record Insertion Wizard to create
00:05an entire data entry form and send the data collected from the user to the
00:09server-side database.
00:11I also showed that there are issues with the sort of code the
00:14Dreamweaver generates.
00:15Most importantly, the data entry form is designed using HTML tables in old-style
00:21HTML architecture, but you can also use Dreamweaver to generate similar server
00:26behaviors and attach them to your own custom forms.
00:30For this demonstration, I'm going to use a custom form that I've created in the
00:35file explorerinsert.php.
00:38You'll find it in the explorers folder, under the current site root.
00:43This file is built with Cascading Style Sheets and XHTML.
00:47Let's take a look at the code structure.
00:51Each of the input controls that collects data from the user is represented by an
00:55input tag. The input tag has an associated label, and all of the labels and
01:00inputs taken together are inside a fieldset tag set.
01:05This represents the most modern approach to building data entry forms - not
01:09relying on HTML tables, but instead on Cascading Style Sheets to format and
01:14place objects on the screen.
01:16I'm also using Spry validation components.
01:20I have one text field for the first name, one for the last name, and two others
01:25for the date of birth and e-mail.
01:26I'll look at the file in Design View and click on each of the
01:31validation components.
01:33The first name and last name only have required validations. The Date of Birth
01:39validation has the date type, and the Email validation has the e-mail type.
01:45I'm going to add one more validation.
01:48The select control for the state column has a single static option with the
01:53text "Select a State," but if I look in the dynamic setting, it shows that it's
01:58filling in the rest of the options from a dynamic record set.
02:02This is the data coming from the MySQL database.
02:06I'll go to the State field and click it, and then go to the Insert panel, to the
02:11Spry category, and I'll locate and click Spry Validation Select.
02:16That adds client-side validation wrapped around the select control.
02:21With the Spry validator selected, I'll go to the Properties panel and give this
02:25a custom name of sprystate, and then to match the behavior with all the existing
02:32form controls, I'll indicate that I want to validate on blur, meaning that if
02:37the user pulls down the list but doesn't actually make a selection, they'll see
02:41a validation message immediately.
02:43I'll save and run the file in the external browser.
02:47If you see messages asking you to copy the file over to the server, say Yes.
02:52Next, I'll click Submit, and I'll show that all of the validators display
02:56their messages correctly, but you'll also see that the field set changes its width dynamically.
03:03If you don't want that to happen, you can fix the field set's width by simply
03:07applying a new Cascading Style Sheet rule.
03:09I'll close the browser and return to Dreamweaver.
03:13Then I'll click on the fieldset object. Take a look in the Tag Selector, and
03:18you'll see that the fieldset is selected.
03:21Then I'll go to the CSS Styles, and I'll make sure that I've selected form.css.
03:26Notice that I've clicked the All button at the top.
03:29This indicates that the rule that I'm about to create will go into this external file.
03:34Then I'll click the Plus button to create a new CSS rule, and I'll see a complex
03:39descendent selector that Dreamweaver has generated.
03:42I'm going to make the selector less specific, because I want to apply this
03:46selector to any object with this ID regardless of where it is in my file, and I'll click OK.
03:53And in the CSS rule definition dialog box, I'll go to the Box category, and I'll
03:59set the width of the object at 450 pixels and click OK.
04:05I'll save all my changes, and once again run the page in the browser.
04:11And now my data entry form has a fixed width from the beginning.
04:15When I click the Submit button, I still see all of my validation messages, but
04:20the width of the container doesn't change at runtime.
04:24So in this video, I've shown you a couple of steps you might want to go through
04:27in preparing your form for receiving data and sending it to the server.
04:32You can use whatever XHTML and Cascading Style Sheet techniques you prefer to
04:38create the look and feel of your data entry form, and most particularly, you can
04:42design the form ahead of time to display any validation messages without
04:46dynamically changing its dimensions at runtime.
Collapse this transcript
Preparing a database table for server behaviors
00:00After preparing your custom forms for data management, the next step is to make
00:05sure your database structure matches the requirements of your forms.
00:09I'm going to go to phpMyAdmin for this step.
00:12If you're working with WampServer, open the Administration menu from the system
00:16tray icon and choose phpMyAdmin.
00:20If you're working with MAMP on Mac OS X, go to the MAMP homepage and click
00:25phpMyAdmin from there.
00:26Then go to the explorecalifornia database and from there, to the explorers table.
00:33Then click Structure, at the top.
00:36This screen shows you everything you need to know about the structure of your database.
00:41For variable character fields, it'll show you how wide the fields are.
00:45It'll show you what data types are being used,
00:48for instance, the dob column is a date field, and most importantly for this
00:52exercise, it will show you which columns you can leave null, or empty, and which
00:57columns require values.
00:59It's very common for there to be mismatches between the database structure and
01:04the requirements of a data entry form.
01:06I'm going to go back to a form that I've shown already, explorerinsert.php in
01:11the explorers folder.
01:13This form contains only a certain number of controls for the various columns.
01:18There are controls for first name, last name, date of birth or dob, e-mail,
01:24address, city, and state.
01:26But there aren't controls for any of the others, and this can cause a problem in
01:30a database table that requires values.
01:33For example, these three columns, username, password, and tours, have their null
01:38property set to No, meaning that you can't leave them blank.
01:43Similarly, the city column is set to No, and the e-mail column is set to No.
01:47If you don't apply validation in the form, you need to match up the requirements
01:52of your data entry form to the requirements of your database.
01:56So I'll show you how to make this adjustment in the three columns that can be
01:59affected by my particular data entry form.
02:02I'll go to the username column, and I'll click the Pencil icon to change it, and
02:08I'll select the Null option, meaning that that column can be set to Null, and I'll
02:13save it, and I'll repeat that process, first for the password, and then for tours.
02:23Just to be on the safe side, you can go through and do exactly the same thing
02:27for the e-mail address and for the city.
02:34I'm going to leave the firstname and lastname set to No, meaning they can't be left null.
02:39And the one column that you must leave set to No is the explorerId.
02:44A primary key column must contain a value;
02:48there are no exceptions to this rule.
02:50So once you've set your database structure and matched it up to the requirements
02:54of your data entry form, you're ready to apply a server behavior to the data
02:58entry form to insert or update data.
Collapse this transcript
Using the Insert Record server behavior
00:00Once you've created a data entry form using your own custom HTML and Cascading
00:04Style Sheets, and prepared your database table to receive inserts, you can then
00:10apply a server behavior to the form.
00:12The server behavior creates all of the PHP code you need to collect the data
00:16from the form and send it to the server.
00:18I am working in the file explorers/explorerinsert2.php.
00:25This version of the form already has all of the data validation I need.
00:28I will show the form in the browser and show you its behavior.
00:32When I click the Submit button, I get validation messages on all of the relevant
00:36text fields and also on the State Select control.
00:41I'll go back to Dreamweaver and then open the Server Behaviors panel.
00:46If you don't see Server Behaviors on the right, as it is in my setup, you can go
00:50to the menu and choose Window > Server Behaviors.
00:55In the Server Behaviors panel, I'll click the Plus button and then choose Insert Record.
01:01In the Insert Record wizard, I am asked for the form that I'm going to collect data from.
01:05There is only one form in this page, and it has a name of explorerForm; the
01:10database connection, and again there is only one explorecalifornia; and then the
01:15table into which I want to insert data.
01:17I'll choose the explorers table.
01:21Just as when using the Insert Record wizard, Dreamweaver detects the database
01:26structure and figures out dynamically what data types will be used in formatting
01:31data to add to the database.
01:33Most of these columns are simple text columns, but the DOB is a date column in
01:38the database table, and so it's going to be formatted as a date in my PHP code.
01:43Also, just like the wizard, I am asked which page I want to browse to after the
01:47Insert operation is done.
01:48I will click the Browse button.
01:51I'll make sure I am in the explorers folder in my current site, and I'll choose
01:56explorerlist.php and click OK.
02:00In a previous video, I described one issue that happens with the generated PHP
02:05code from Dreamweaver.
02:07When you're working with date values, Dreamweaver isn't very good at
02:10formatting the date as needed for MySQL, and I showed you in that video how to
02:16write a little bit of custom PHP code that would collect the data correctly
02:20and format it for MySQL.
02:22Now I am going to show you how to create that code in a reusable form.
02:27In the _includes folder, I've created a file named formfunction.php.
02:33The folder is _includes under the site root, and I have made a copy of two parts
02:38of the PHP code for my previous exercise.
02:42I have a require_once command that includes the Zend library's date class, and I
02:48have also included a copy of the GetSQLValueString function, and in the case for
02:54the date type, I've added the custom code that retrieves the data expecting the
02:59format that the users has to type in:
03:01month, day and year, and reformated it as required by MySQL.
03:05Here is how I will use that file in the generated PHP code in my data entry form.
03:12I will return to the file explorerinsert2.php and go to Code View, and up at the
03:18top, after the require_once command for the connection, I'll add another PHP
03:24code block and another require_once command. And I'll include that file
03:28formfunctions.php, using the relative address ../_includes/formfunctions.php.
03:40I'll close the name of the file, the require_once command, add the semicolon and
03:45close the PHP code block.
03:47Now in my newly generated code in this file, I have another version of the
03:51GetSQLValueString function.
03:54I don't need to remove that function definition because it's wrapped inside this
03:58conditional block, asking whether the function already exists.
04:02Because I've now included the version from the formfunctions file, this
04:06definition will be ignored, and the version that has the correct date formatting
04:11will be used at runtime.
04:13I'm ready to test my form.
04:14I'll save my changes and run the page in an external browser.
04:19If you're prompted to copy files to the server, say yes.
04:22I'll type in some names.
04:23I'll type in a date of birth using the required date format.
04:26I'll use 6/23/2009.
04:31I'll add an e-mail address.
04:35I'll ignore the Address and City this time, because the form doesn't require
04:39them to be entered, and I have set up my database now so that they can be left
04:43blank, and I will choose a State.
04:45Then I will click Submit, and I'll be taken back to my list page, and I'll show
04:50you that the date was entered correctly because of the revised and customized
04:55date formatting in my PHP code that was included from that separate file.
05:00So in this video, I have shown you how to use the server behavior for inserting
05:04a record and apply it to an existing data entry form.
05:09I've also shown you how to handle the special case of date formatting to allow
05:13the user to type in a date value in whatever format you choose.
05:18You simply need to match the format of the date as expected when you create your
05:22Zend date object and match it to the validation rule in your form.
05:29Then you format the date correctly, as expected by MySQL.
05:33The result is a very simple data entry form that collects the data from the
05:36user, formats it correctly, and then sends it to your MySQL database.
Collapse this transcript
Preparing an update form
00:00Just as with inserting data into a database, you can create a data entry form to
00:05update data using Dreamweaver's update record server behavior.
00:10Before you use the server behavior though, you need to prepare the form to
00:13display data from a single record that the user wants to update.
00:16I'll be working in the file explorerupdate. php, in the Explorers folder of my site root.
00:23The first step is to add a binding, or recordset to the form, to retrieve a
00:27single record from the database table.
00:29I'll go to the Bindings panel and click plus and choose Recordset or Query.
00:35I'll give my recordset a name of rsExplorer.
00:39Notice I am using the singular version of Explorer, rather than the plural
00:43version, because I am only going to retrieve the single record, filtered by the
00:47primary key of the table.
00:48Then I'll choose the Explorers table. I'll click Selected, and then holding down
00:54Ctrl on Windows or Command on Mac, I'll select only the fields that I want to
00:58display in the form:
01:00the explorerId, firstName, lastName, dob, email, address, and make sure that
01:08I've also selected the state.
01:10I am going to filter.
01:11I'll pull down the list of available columns and choose the primary key
01:15column for this table, explorerId.
01:18The default SQL statement will be designed to retrieve a single record,
01:22filtered on the primary key column, explorerId, looking for a URL parameter,
01:28known in PHP as a Get variable, and by default, the name of the variable will
01:33be the same as the column name;, explorerId.
01:36I'll click the Test button and provide a test value for the primary key.
01:41I'll provide a value of 1.
01:44I'll click OK, and I'll see that I've retrieved all of the columns I need to
01:48fill in my data entry form.
01:51I'll click OK, and click OK again, and that adds the SQL statement or
01:56recordset to the form page.
01:58I'll add information to the form controls to cause them to display the values
02:03from the retrieved record.
02:05I'll start with the First Name column.
02:07I'll click on the text field and then go down to the Properties panel.
02:11I'll click the Bind to Dynamic Source button,
02:14the lightning bolt for that column, and I'll choose the matching column in the database,
02:19the First Name column in the rsExplorer Recordset, and click OK.
02:25I'll do the same thing for each of the other text fields:
02:28The Last Name, and Date of Birth, the Email address, the Address, and the City.
02:43If for any reason I've forgotten one of the columns, as I have here, I can cancel
02:47out, go back to the Bindings panel, double-click on the recordset to reopen it,
02:53and then, holding down the Ctrl key, I can select the column that I missed.
02:58Make sure you're holding down Ctrl on Windows or Command on Mac when you do the
03:02click; otherwise, you will deselect everything else.
03:04I'll click OK, and that updates the recordset in the page.
03:09Go back to the City field, and once again click the Bind to Dynamic Source
03:14button, and now I should be able to choose the City column.
03:19You can also set the current value for a select control.
03:23I'll click on the State select control, and I'll go to the Properties panel and
03:27click Dynamic. And then for set value equal to, I'll click the lightning bolt
03:32button, and I'll choose the matching column, state.
03:35I'll click OK and click OK again, and now my data entry form will match whatever
03:42value is passed to it when the file opens.
03:45There is one more column though, that you need to account for.
03:48When you're working with an HTML data entry form for managing data, you have to
03:52pass the primary key value of the current record from the form to the action,
03:58that is to the page that's going to process the request by the user.
04:02You do this with a hidden data entry form field.
04:05I'll click right after the Submit button in the form, then I'll switch to Code
04:09View, and I'll check the location of the cursor.
04:13You need to make sure that the cursor is inside the form.
04:16A hidden field won't affect the appearance of the form at all, but if it's
04:20placed say outside the form, where I have placed the cursor now, the value won't
04:24be passed from form to action.
04:26So I'll place the cursor right before the ending form tag. Then I'll go to the
04:30Insert panel and choose Forms, and I'll add a hidden field.
04:36Because I'm in Code View, I get the Tag Editor Dialog box.
04:40I'll click OK, then go back to Design View and show you that the hidden form
04:45field is displayed by this icon in the upper-right.
04:48Again, don't worry about its visual appearance, or its placement on the screen;
04:52because it's hidden, it will be invisible to the user.
04:55I'll select the Hidden Field that I created, then I'll click into the
04:59Properties panel, and I'll assign the name matching the name of the database
05:03column for the primary key, explorerId.
05:07Don't worry about the case.
05:09It doesn't matter whether it's uppercase, lowercase, or mixed case.
05:13It just has to match the name of the database column in the table.
05:17Then I'll go to the value, and just as I did with the text fields, I'll click the
05:22Dynamic button, and I'll match this controls value to the explorerId column in
05:27the recordset, and I'll click OK.
05:31If you save and test the form at this point, it won't be quite right.
05:34I'll click and preview,
05:38and you'll see that the form is displayed with nothing in it. Here is why.
05:42Let's take a look at the generated code.
05:44I'll go to the Code View, and then I'm going to press Ctrl+F on Windows or
05:49Command+F on Mac, and I am going to search for rsExplorer.
05:52I'll click Find Next, and you'll see that you may not get to the actual
05:57definition of the recordset. But if you click Find All, you'll get a listing of
06:01all references, and here is the code I am looking for.
06:05There is a variable that's generated by Dreamweaver called colname_rsExplorer,
06:10which is set to a default of -1.
06:13In the Search panel, I'll double-click on that bit of code, and that takes me to
06:16line 40 in my page, where the value is being set.
06:21This is the default primary key value for the record that will be displayed in
06:25the form. Because I am not connecting this page to the rest of my data entry or
06:29data management system yet, I'm just going to change this value so that I am
06:34displaying the data from the first record in the table.
06:38I'll change the default value of the primary key column from -1, which
06:42means I am not retrieving anything, to 1, which means I am retrieving the record
06:46with that primary key value.
06:49I'll save my change, and then I'll preview the page in the browser, and now I
06:54see the data from the record with a primary key value of 1.
06:59There is one more step to follow, which is updating the date format, and I'll
07:02show you how to do that in another video.
Collapse this transcript
Using the Update Form behavior
00:00Once you've prepared you data entry form, you can apply a server behavior to
00:04it, to collect the data from the form, and then update a record in the
00:08server-side database table.
00:10For this exercise, I'll use the file explorerupdate2.php in the explorers
00:15folder of the site root.
00:17This page is designed to retrieve a single record from the database table and
00:21display it in the browser.
00:24The user can make changes to the data and click Submit, and the data should then
00:28be sent to the server.
00:29There is a problem with this form, though.
00:32When I click the Submit button, I get an Invalid Format message on the date, and
00:37that's because this data entry form is designed to validate the date and look
00:41for it in the format of month/day/year.
00:42So we have to reformat that value before we present it in the form.
00:49I'll close the browser and return to Dreamweaver, and go to Code view.
00:56Now, in the previous exercise, I showed you a file that's a part of the
01:00_includes folder, named formfunctions.php.
01:04This file has a require_once that includes the Date class from Zend framework.
01:09And then down at the bottom it has a function we're now going to use,
01:13called dbDateToFormDate.
01:15It accepts a single variable, named formDate, casts it in a Zend_Date object, and
01:22then reformats it and returns it in the form of month/day/4-digit year.
01:28I am going to use this function so I can format the value correctly.
01:34I'll use this function in my form page.
01:36I'll go to the form and scroll all the way up to the top, I'll place the cursor
01:41after the PHP require_once command for the database connection, and I'll add
01:46another PHP code block.
01:49Within the code block I'll add a require _once function call, and I'll call the
01:54file ../_includes/formfunctions.php.
02:02So now, the two functions that are in that file, the correct version of
02:06GetSQLValueString and the function that I am going to use to format the date in
02:11the form, are both available to this page.
02:14Now I'll go to Design View, and I'll go to the Date of Birth field.
02:18I'll click it and then go to Code View, and this helps me find the code I am
02:24looking for in the code.
02:26I'll go to fullscreen and then in order to present the date in the
02:30correct format, I'll go to the PHP command that's outputting the value in the form control.
02:36This is the expression that's being output now, the DOB column in its raw form.
02:41I am going to wrap that expression inside my custom function that's in the included file.
02:48It looks like this.
02:49I'll start with dbdate. Then I'll press Ctrl+Spacebar and using Dreamweaver's
02:54code hinting, I'll select the correct function name, dbDateToFormDate.
03:00Then I'll place the cursor after the expression - that retrieves the data from the
03:03database - and I'll add a closing parenthesis.
03:08I should now see that there are no syntax errors in my PHP code.
03:12I'll save and run the page in the browser.
03:16And now the date is formatted as the form expects it to be and also as the
03:21function expects it to be in order to cast it to MySQL.
03:25Now I am ready to apply the server behavior.
03:27I'll go back to Dreamweaver to Design View, and I'll look at my panels by
03:33pressing the F4 key.
03:34I'll go to Server Behaviors, I'll click the Plus button, and I'll choose Update Record.
03:42I'll check the values in the first two items. I am submitting the values from
03:45the only form in the page, explorer form, and I am using the explorecalifornia
03:50database connection.
03:52I'll pull down the list of tables and choose explorers, as before, and then I'll
03:59check all of the mappings of form controls to database table columns.
04:04For example, the explorerId form control, the hidden control, is used to
04:09select the record to update, and all of the other table columns get their
04:13values from various controls.
04:15Dreamweaver matches this all up automatically because I have matched the names
04:19of my form controls to the names of the database columns.
04:23If you haven't matched them in the same way, you can still use the server
04:27behavior by manually matching the columns to your form controls.
04:32As with other server behaviors and wizards that I've shown in this chapter, you
04:37can also tell Dreamweaver to set up code to go back to a particular page after
04:42the update operation is done.
04:44I'll click Browse, and I'll choose explorerlist.php and click OK.
04:50I am ready to test the Update feature.
04:53I'll save my changes, and I'll run the page, and I see that the First Name is
05:00Jackie and the Last Name is Smith.
05:01I am going to change the Last Name from Smith to Jones, and I'll change the Date
05:06of Birth from 7/10/1985 to 7/10/1981.
05:11I'll change the Email address from jackiesmith to jackiejones, and you can make
05:15other changes if you like.
05:17I'll click Submit, and I'll see that I go back to the explorerlist page, and the
05:23Jackie Jones record has been correctly updated.
05:25So that's a look at how to prepare a data entry form for use with an update
05:30operation and how to apply the Dreamweaver update record server behavior to
05:35minimize the amount of hand coding you have to do of PHP, and also how to
05:40integrate features of the Zend framework to make it easier to format your
05:44date values.
Collapse this transcript
Creating list page links to edit and update data
00:00Once you've created a list page and data entry forms for inserting and updating
00:04data, you can then tie the whole thing together by adding hyperlinks to the list page.
00:09The user will be able to click the links to navigate to the forms.
00:13I'll start this demonstation in the file explorerlist.php, in the
00:17explorers folder of the site.
00:19Looking at the file in Design View, I'll click on the Live View button and show
00:24that the page is successfully retrieving and displaying data from MySQL.
00:29I'll exit Live View and then click to the right of the HTML table, and I'll
00:34press Enter or Return to create a new paragraph.
00:37Then I'll type some text that the user will be able to click on to navigate
00:41to the insert form.
00:42I'll type the text Insert New Explorer.
00:45Then I'll select that new text and go to the Properties panel.
00:48I'll make sure that the HTML category is selected and then I'll create the
00:53hyperlink using either the Point to File or the Browse for File tools.
00:58For this demonstration, I'll use Point to File.
01:01Make sure that the file you want to link to is visible in the Files panel.
01:06I'll be linking to the prebuilt form, explorerinsert2.php.
01:11Click and drag the Point to File tool and drop it onto the target file.
01:15That creates the hyperlink.
01:18Then I'll save and run the page in an external browser.
01:22If you followed these steps and you're prompted to copy the file to the
01:25testing server, say Yes.
01:28In the page in the browser, here's my new link.
01:30I'll click that link and that takes me to the insert form.
01:34And then I'll type some values.
01:36I'll set the first name to New and the last name to Explorer.
01:41I'll set the date of birth to 12/23/1996.
01:42I'll set the e-mail address of new@ explorer.com, I'll leave the address and city
01:52blank and I'll set the state to California.
01:56I'll click Submit, and that causes the form to navigate back to the list page
02:01and I'll see that my new data has been inserted into the database successfully.
02:06So an insert hyperlink is very simple.
02:09You're just navigating to the form that's going to do the insertion, and then in
02:13the form's insert logic, you're navigating back to the list page after the
02:17data's been added to the database.
02:19Editing data is a little bit more complex.
02:22You'll need to add a hyperlink to each row of the dynamic HTML table.
02:27You can either create a new column and create hyperlinks on a particular
02:31word like Edit, or you can create hyperlinks on existing data, such as the first name.
02:36That's what I'll do.
02:38I'll go back to Dreamweaver and then I'll click on the first name column of the
02:44rsExplorers record set.
02:46You only need to click on this value;
02:49you don't need to double- click and you don't need to drag.
02:52Then with the value selected, I'll go down to the Properties panel, just like I
02:55did for the insert link and this time I'll use the Browse tool.
02:59I'll click Browse for File, in the correct site root.
03:02In this case it should be 07_managingdata.
03:06Then drill down to the explorers folder and choose the prebuilt version of the
03:11update form, explorerupdate2.php.
03:15So that added a simple hyperlink to the selected text.
03:19But you can actually add logic to pass a variable very easily from the Browse dialog.
03:25I'll click the Browse button again and then down toward the bottom of the dialog
03:29I'll click the P arameters button.
03:31In the Parameters button you add an name and a value for each value that you
03:36want to pass to the update form.
03:38You must pass the primary key value to the update form so that it knows
03:42which record to display.
03:44I'll set the name of the parameter to explorerid, all lowercase.
03:48Then I'll click in the Value column and click the lightning bolt and then if
03:52it's not already open I'll open up the record set tree, and I'll choose the
03:56primary key column explorerId.
03:59I'll click OK, click OK again, and click OK a third time.
04:05Then I'll go to Code View and show you the resulting generated code.
04:10The HREF attribute starts with the name of the file I'm navigating to and then
04:15after a question mark passes the variable named explorerid and sets its value to
04:21the column explorerId.
04:24Now one very important thing that you have to check is that because PHP
04:27variables are case-sensitive, you must make sure that the variable that you
04:31pass from this page matches the spelling of the variable you're expecting in the target page.
04:37So now I'll go to the Diles panel and open explorerupdate2.php, and make sure
04:43you're looking at it in Code View.
04:46Then scroll down in the file to lines 69 through 71.
04:50This code was generated by Dreamweaver.
04:53Notice that in Dreamweaver it matches the name of the variable to the name of
04:57the database column.
04:58And if your database column has any uppercase characters, it uses those.
05:02I usually like to set all my variables with all lowercase.
05:06So to make sure that the two match, in the isset function I'll set explored to
05:11all lowercase there.
05:13And then I'll do the same thing on the next line.
05:16So now the spelling of the variable in the target file exactly matches the stone
05:20of the variable in the sending file.
05:24I'll save my changes in both files and then just to be sure that they've both
05:28been copied to the server, I'll go to explorerupdate2.php and look at it in Live View.
05:35It'll open up to default record, that is, the record with a primary key value of one.
05:41Then I'll exit Live View and I'll go to explorerlists.php and I'll open this
05:46file in the browser.
05:48Now I should be able to click on any link, and I should see this selected record.
05:54I'll click on New for New Explorer.
05:57And when the form opens it shows me that record.
06:01I'll set the first name value from New to Revised and I'll click Submit.
06:07And when the form's logic is completed I'm sent back to the list.
06:11And I'll see that the data has been revised.
06:14I'll also use this opportunity to fix the first row of my data, which I had a
06:18problem with in a previous exercise.
06:21I'll click on Joey in Joey Adams and I'll set the date of birth to 4/15/1993.
06:29I'll click Submit, and when I return to the list page, I see the data correctly display.
06:35So that's a look at how to tie the components of the data management system together.
06:40From the list page you put in a simple hyperlink that takes you to the insert
06:44form and you also add in a dynamic URL for each record that passes a query
06:50string or a GET variable to the update form.
06:54The update form then displays the existing data, the user can make whatever
06:58changes are required, and then when they submit the changes they're saved to
07:02the database.
Collapse this transcript
Using the Delete Record server behavior
00:00The last step in creating a data management system is to give the user a way to
00:05delete data from the MySQL table.
00:07I'll start this exercise by creating a completely new file.
00:12I'll select File > New and then create a new blank PHP page.
00:18I'll go into Code View, and I'm going to delete all of the HTML in the page.
00:23The user will never see this page rendered in the browser.
00:27It will execute a backend database operation to delete a record and then
00:31immediately return to the list page.
00:36Then I'll save the file into the same folder that contains my other data
00:39management pages, and I'll name it explorerdelete.php.
00:45I'm going to add a server behavior.
00:47I'll go to the Server Behaviors panel, click plus, and choose Delete Record.
00:54In the Delete Record dialog, I'll check my Connection and then set the Table to Explorers.
01:00I've accepted the settings for the Primary key column and value, and then
01:05indicate that after deleting, I want to go to explorerlist.php.
01:10When I click OK, all of the required PHP code is added to the page.
01:16Down at the bottom, PHP first checks to make sure that I have a variable named explorerId,
01:22a Get variable that will be passed from another page.
01:26It also makes sure that this variable isn't blank, and then if that's all
01:30true, it executes a deleteSQL statement, removing the requested record from
01:36the database table.
01:37Down at the bottom, it sets a variable, indicating which page we want to navigate
01:41to, and then using this command, header, sprintf, Location, deleteGoTo, it
01:48redirects the browser to that page.
01:51In the page's current state, watch what happens if I browse it directly.
01:54I'll run the page in the browser, and I see that the page is blank.
02:00The problem is with the logic.
02:02If this condition in the 'if' statement turns out to be false, PHP simply is
02:07told, jump past all this code and don't do anything.
02:11To fix this, I'm going to take everything starting with the setting of the
02:15deleteGoTo variable, all the way through the header command.
02:18I'll cut it to the clipboard, and then paste it after the closing brace for
02:23the 'if' statement.
02:24I'll then select most of the code and press Shift+Tab and then do a little bit
02:29more tabulation to make the code look right.
02:33If the page is called directly from the browser for some reason, instead of just
02:37showing a blank page, it will navigate to the list page.
02:41So now my page is ready to delete records.
02:43I am going to call this page from the list page.
02:47I'll go to explorerlist.php and look at it in Design View.
02:53In Design View, I'll click and drag down to select the entire final column in the table.
02:59Then I'll right-click and choose Table > Insert Rows or Columns.
03:05Don't choose Insert Column here, because it would insert a column before the
03:09current selected column.
03:11If I choose Insert Rows or Columns, I have the option to insert a new column
03:15either before or after the current column.
03:17I will choose Columns, and one column after the current column, and click OK.
03:23Then I'll click into the final column into the second row,
03:27the row that contains the data, and I'll type the word "Delete."
03:32I'll select the word "Delete," and then go to the Link box, and I'll browse and
03:37select my new file, explorerdelete.php.
03:41Now I'll go to Code View.
03:44Just as with the Update command, I need to pass a variable, which I'll name
03:48explorerId, to the receiving page.
03:51The easiest way to do this is to take the existing code that I already put
03:55into the Update command.
03:57So I'll go to the explorerupdate2.php href.
04:01I'll start with the question mark, and I'll take everything through the output
04:06of the explorerId column.
04:08I'll copy that to the clipboard. Then I'll go down to my new
04:13explorerdelete.php href,
04:16I'll right-click there, and paste.
04:20I'm ready to test my delete operation.
04:23I'll save and run the list page,
04:26and when the list page is displayed, it shows a delete item for each record
04:30in the database table.
04:32I'll click Delete for my Revised Explorer record.
04:35You will see that it doesn't work quite right yet.
04:38So, I am going to go back to my list page, and I'm going to change the case of
04:42the variable that I'm passing from one page to another, so that it has an
04:46uppercase I instead of a lowercase i.
04:48I'll run the page in the browser again, I'll click Delete, and now the record
04:55is correctly removed.
04:57It's important to match the case in the variable name and in the code that's
05:01looking for the variable in the Delete page.
05:04So now you have the ability to insert new records by clicking the Insert New Explorer link.
05:09You have the ability to update records by clicking on the First Name of any
05:13record, and you also have the ability to delete data from the MySQL database by
05:18clicking on the Delete links.
05:19Dreamweaver has generated most of the PHP code we needed, but I have made minor
05:25alterations, and along the way you've learned a good bit about how to write PHP
05:29code to manage data in a backend MySQL database.
Collapse this transcript
8. Authenticating Users with PHP
Creating a login form with a PHP server behavior
00:00Web sites that allow users to manage data on the backend - such as using Insert,
00:05Update, and Delete operations - frequently need to be authenticated.
00:10Dreamweaver CS5 gives you the ability to create simple login forms and then
00:15protect your pages from unauthenticated users.
00:18For all of the exercises in this chapter, I'll use a version of the web site
00:22stored in 08_authenticate folder, under Exercise Files.
00:27If you have access to the exercise files, go into Dreamweaver site setup, and
00:31point your site at this folder.
00:34I'll start in this file, login.php, which you will find in the login folder of the site root.
00:40This file has a simple data entry form with two controls:
00:44User Name and Password.
00:46Notice that both are wrapped in Spry validation controls.
00:51I'll run the page in the browser and show you that if I try to submit the form
00:55without entering any values, I'll get client-side validation messages.
01:00In order to use the form, I would need to type in values and then compare those
01:05values to the backend database.
01:08Right now, the data entry form doesn't do anything to work with the backend database.
01:13If you look at the code, you'll find that it's all either Cascading Style
01:17Sheets or HTML code.
01:19There is the inclusion of the Spry validation, JavaScript, and Cascading Style
01:23Sheets files, and another Cascading Style Sheet file that controls the
01:27appearance of the form,
01:29but all of the work to collect the data and compare the values to something in
01:33the backend still has to be done.
01:35I'll go back to Design View.
01:38Before I apply the behaviors that are going to execute the login functionality,
01:44I'll first double-check my database connection.
01:47I'll go to the Databases panel and then double-click explorecalifornia.
01:52If you're working with WampServer on Windows, all these settings should be correct.
01:58If you're working with MAMP on Mac OS X, set the password to root, and then
02:04test your database.
02:06If you see this message on Windows, click OK and test again.
02:11Once you've seen the message that the connection was made successfully, you can
02:15click OK and click OK again, and you'll be ready to work with your database.
02:21To attach the form to the backend database, go to the menu and choose Insert >
02:27Data Objects > User Authentication.
02:31There are four operations available: to Log In and Log Out User, Restrict Access
02:36To Page, and Check New Username.
02:40I'll choose Log In User.
02:42In the dialog that appears, I indicate which form I want to get the
02:46information from on the page,
02:48and the names of the fields or data entry controls in the form.
02:52I've named my controls User Name and Password. Then I indicate how I want to do the validation.
02:58I'll select the explorecalifornia connection, and set the Table to admin.
03:05The admin table has three columns, named adminId, userName, and Password.
03:10adminId is a meaningless primary key.
03:14I'm not going to use that.
03:16I'll set the Username column to userName and the Password column to password.
03:22Now I'm going to define what happens if the login succeeds or fails.
03:26If I load the form page directly in the browser, and the login succeeds, I'd
03:31like the user to go to the web site's homepage.
03:34So I'll click Browse, and then I'll go to my site root folder.
03:39If you are not sure whether you are in the site root folder, just click the
03:42button, Site Root. Then I'll locate and select the file index.php and click OK.
03:51If the Login form is loaded as a result of an unsuccessful attempt to load a
03:55protected page, after the login operation is complete, I'd like to go to the
04:00originally requested page, known here as the previous URL.
04:05To do that, all I have to do is check the check box. And finally, if the login
04:10fails, I want to go back to the login form again.
04:14So I'll click Browse and then from the site root, I'll go to the login folder,
04:20and I'll choose login.php.
04:24You can restrict access to various pages of your web site based on a user name and password.
04:29That would mean that if the user logs in at all, that they can get access to the
04:33pages. Or you can also apply access levels.
04:37I won't get into access levels here, but it's worth noting that if you want to
04:42use access levels, you need to structure your database table to include a
04:46numeric, or string value.
04:49I've selected the default User Name and Password, and now I'll click OK.
04:55Before I test the page, let's take a look at what's in the database.
04:59I'll go to the Databases panel, to the explorecalifornia connection, and open
05:04the list of tables.
05:06Here's the table that contains the names and passwords for my users.
05:11I'll right-click on the table, and choose View data and show that the table
05:15contains only one record.
05:17The user name is explorerone, and the password is password.
05:23I'll click OK, and then I'll open the page in the external browser.
05:28If I don't type anything in, I'll get client-side validation errors generated by
05:33the Spry controls in the form.
05:36If I type values in that aren't recognized in the database, such as noname and
05:41nopassword, and then click Submit, the client-side validation errors are
05:46cleared, but the login page is simply reloaded.
05:50But then I'll type in the valid values, explorerone as the User Name and
05:57password in all lowercase, as the password, and this time when I click Submit, I
06:02am taken to the homepage of the web site.
06:05So the data entry form is now designed to collect the information from the user,
06:10compare it to the contents of the database, and then if the login operation
06:15succeeds, to take the user to the homepage.
06:19Once you've implemented the login form, you can then start to protect the pages of
06:23your web site one at a time, and I'll show you how to do that in another video.
Collapse this transcript
Protecting page access with PHP server behaviors
00:00Once you've created a login form for your web site, you can then protect
00:04individual pages so that only users who have logged in can view them.
00:09For this demonstration, I'll use the file explorerlist.php in the explorers
00:13folder, under the chapter 8 site root.
00:17With the file open on the screen, I'll go to the menu and choose Insert > Data
00:21Objects > User Authentication.
00:24From there, I'll choose Restrict Access To Page.
00:28On this screen, I am asked to check whether a user has already logged in.
00:31You can either choose to protect based on a username and password or a username,
00:36password, and access level.
00:38I'll use the default setting, and that means that anybody who is logged in will
00:42be able to view the page.
00:44Then for users who haven't logged in, I'll indicate which page I want them to see.
00:49I'll browse, make sure I'm at the site root, go to the login folder, and choose
00:57my login form, login.php, and then I'll click OK.
01:01I'll save my changes, and I'll run the page in the browser.
01:08And now, instead of going to the page I requested, I am sent to the Log In form.
01:13If you're working on Mac and you're having trouble previewing the file, go back
01:17to the first video in this chapter and make sure you followed the instructions for
01:21updating your database connection.
01:23It might be that you're having trouble connecting to the database.
01:26Let's take a look at the code that was generated.
01:29I'll go back to the page in Dreamweaver and look at Code View.
01:32Up at the top of the page, there is a bunch of new PHP code. Here are some of
01:37the critical pieces.
01:39This conditional code block checks to make sure that a session has been started.
01:43The nature of a session is that it tracks a particular user, as long as they
01:48keep their browser open.
01:50Information is passed from page to page using something called a cookie.
01:55You don't need to worry about how this works; it's all handled automatically by
01:59PHP and the browser.
02:01But it is important to note that in PHP any page that you need to protect or any
02:07page that you need to put information into the session must call the
02:11session_start function.
02:13Once that function has been called, this session associative array known as
02:18$_SESSION is created.
02:20And so this expression is set, $_SESSION returns true, if the session has
02:26started and false if it hasn't been.
02:30The rest of the code examines whether the current user has logged in, and then
02:34indicates with this variable, MM_ restrictGoTo, which page should be navigated
02:39to if the login fails.
02:42That's pretty much it.
02:43If you want to apply this page restriction to all of your pages, you could copy
02:49this PHP code block, starting here at line 2, and going down to the end of the
02:55code block at line 46 into a separate PHP file, and then you could include that
03:01file in all of your other pages throughout the web site.
03:04I'm going to keep this demonstration focused on a single page though, so that we
03:08can see how the code that's generated by Dreamweaver works in its default state.
03:14Now, to complete the cycle, I'll preview the page in Firefox.
03:18And now, I am going to log in with my user name and password, explorerone and
03:24password, and I'll click Submit.
03:28As long as I keep the browser open, I'll be able to navigate around
03:32throughout the web site.
03:34I can go to the Insert form and back.
03:37I can click Delete and delete a record, and I can also update data.
03:42If I close the browser though, and then restart the page, I'll see that my
03:47session has started over, and I am sent back to the Log In form.
03:51Again, you can either protect each page individually, or you can take this
03:55generated code that to remove your places at the top of a page, move it into its
04:00own PHP file and then include it in all the pages that you want to protect.
04:05The default behavior is that any user who is logged in at all can see the
04:09protected pages, but you can also apply access levels, if you desire, to create a
04:14more granular security model.
Collapse this transcript
Logging out with a PHP server behavior
00:00In other videos in this chapter, I've described how to build a login form and
00:05compare values that the user types in to values in the database,
00:09and then I showed how to protect various pages of your web site, so that
00:13unauthenticated users can't see them.
00:16Now, I'm going to show you how to create a log out link that allows a user to
00:20explicitly log out from the web site.
00:23I'm working in the file explorerlist.php in the explorers folder of the current site root.
00:30When you create a log out operation, you can either add a link to an existing
00:34page, or you can create an external log out page.
00:38I'm going to use the first option,
00:40adding a log out operation to a single page.
00:44I'll scroll down in the page to the Explorers section and click after the last
00:48item under the Explorers menu, Video Podcast. Then I'll go to Code View.
00:54I'm going to add a new list item after the video podcast.
00:58I'll click after the ending tag for </li>, and then I'll create a new <li> tag
01:04set, and place the cursor between the tags.
01:08Now I'm ready to create my log out operation.
01:10I'll go to the menu and choose Insert > Data Objects > User Authentication > Log Out User.
01:19You can attach the log out operation to any of the links in the page, or you
01:24can create a new link.
01:25I'll choose that option, creating a new link with the text "log out."
01:30If you were creating an external separate log out page, you could instead select
01:35the option to log out when the page loads. Then you must select a page to go to
01:40after the log out operation is complete.
01:42I'll click Browse, go to the site root, to the login folder, and I'll choose the
01:48login form page login.php, and I'll click OK.
01:54This page is already protected.
01:56If I try to view it in the browser directly, I'll be redirected to the login form.
02:00So let's take a look at the entire set of functionality.
02:04I'll try to load the page in the browser, and because it's protected, I'm taken
02:08to the Log In form.
02:10In the Log In form, I'll type in my username and password, and I'll click
02:15Submit, and I'm taken to the index page.
02:19As long as I keep the browser open, I can navigate around to all of the protected pages.
02:24But here is my new Log Out link and when I click it I'm logged out, and I am
02:29returned back to my Log In form.
02:32Once again, you can take a look at the code that's generated by Dreamweaver,
02:36and if you like, you can move it into external pages and include it in others to
02:40make it more reusable.
02:42In this page, I now have some code at the top that indicates how the login
02:46operation will work.
02:47The most critical part is this query string variable, named doLogout, set to a value of true.
02:54When I click on the link, that variable is passed to the page, and then the
02:58second time the page is loaded, as a result of that variable existing and
03:03being set to a value of true, all of the operations needed to log the user out are executed.
03:09A number of variables in the session scope are cleared from memory.
03:13And then there is line of code that sets a variable, named logoutGoTo, which in
03:17this case is set to my login form, and finally, a call to the header function is
03:22used to redirect the browser to the login form.
03:26You can take all of that code, move it to an external file, and then include
03:30it in whatever pages you need it in, to make the code more reusable throughout your web site.
03:35This architecture allows you to easily create a complete security system for your web site,
03:40attaching it to the information you store in your database.
03:44Your database should have a table containing user information, minimal username
03:49and password, and optionally, access level, and then you can design your security
03:54model, integrating the database with all the pages of your site.
Collapse this transcript
9. Deploying a Dynamic Site to a Remote Server
Configuring a remote server with FTP credentials
00:00Once you've completed and tested your PHP-based site on your local computer, you
00:04can deploy it to your remote site.
00:07I'll start by showing you how to configure the remote site, and how to set it up
00:11to work with the remote site over FTP, or File Transfer Protocol.
00:15For the purpose of this demonstration, I'm using an FTP server called FileZilla.
00:20It's a Windows-based, free FTP server which you can get from the web, and it's
00:25very easy to set up and install.
00:28I've configured a single user on the server.
00:31The name of the user is ftpuser, and I'll show you that under Shared folders,
00:37it's pointing to a folder named remote, under my web root.
00:41So for demonstration purposes, I'm working with the same installation of
00:44Apache, MySQL, and PHP, as I am for my local server, but I'm pointing to a
00:50different directory.
00:52I'll close the User configurationscreen in FileZilla and then minimize it
00:56to keep it running.
00:58Now, if you're working on Mac OS X, you can instead use the FTP capability
01:02that's built into that operating system.
01:05Go into your System Preferences, to Sharing, to File Sharing, and then under
01:10Options, you'll be able to turn on the FTP capability.
01:13Or if you'd like to apply these skills to an actual remote site, just get
01:18the FTP credentials from your Internet Service Provider, or your web server administrator.
01:24I'm working with a site named 09_deployremote.
01:29I'll go to the menu and choose Site > Manage Sites, and then click Edit to look
01:35at the Site preferences.
01:38I'll go to the Servers category on the left.
01:41When I first configured the site, I created a local server definition.
01:46Now I'm going to add a new server definition for the remote server.
01:50I'll click plus, and I'll name this Remote Server.
01:54You can connect using a variety of protocols, but almost all the time you're
01:58going to use FTP, or File Transfer Protocol.
02:02The FTP Address can either be the DNS name or the IP address of your remote server.
02:08I'm going to use the IP address, 127.0.0.1.
02:14Then I'll type in my username, ftpuser, and the password that I created with it. Then I'll test.
02:21If your FTP server is running, you should connect to your server automatically.
02:27If you have any troubles, the first thing to try is to go into More Options and
02:31try selecting Use Passive FTP, and then click Test again.
02:36If you're still having trouble, check Adobe's web site. Go to the Dreamweaver
02:41Support site, and type in connecting with FTP, and you'll find a knowledge-based
02:46article that should help.
02:48My username is already connected to the correct directory, so I don't need to
02:52put any information here under Root Directory.
02:55I'm also setting the web URL to point to the remote folder under the localhost.
03:01For a remote FTP server, you won't use this value, but it's a good idea to
03:05have it be accurate.
03:06Then I'll click Advanced, and I'll check to make sure that I have this option,
03:11Maintain synchronization information, selected.
03:14This will allow me to easily synchronize my files between the client and the remote site.
03:20And as with the testing server, I'll set the Server model to PHP MySQL.
03:27I'm not going to turn on the other options.
03:29This one, Automatically upload files to server on Save, will cause all changes
03:34to be uploaded immediately upon saving them.
03:37I typically don't like to do that.
03:39You can, if you like, use the file checkout capability.
03:42This results in placing file locks on files on your remote server, so that only
03:47one user can check them out at a time.
03:51I'll click Save, and then I'll check to make sure that my new server is marked as
03:55the remote server and not as the resting server, and I'll click Save.
04:00Then I'll click Done, and I'll go to my Files panel.
04:05Right now, I'm looking at the Local View,
04:08that is the set of files that I've been managing through Dreamweaver already.
04:12I'll switch to the remote server and show you that that folder is empty, and
04:17I'll show you the physical folder on the server, which on Windows is
04:21wamp/www/remote, and show that it's starting off as an empty file also.
04:29If this folder doesn't already exist on your local computer, you should create
04:33it now, and then you'll be ready to upload files to your server and synchronize
04:37the files between the client and the remote server whenever you need to.
Collapse this transcript
Synchronizing site assets with the remote server
00:00Once you've configured and tested your FTP connection, you can upload your
00:04entire site to the remote server with a single step in the Files panel, or from the menu.
00:11I'll work primarily with the Files panel in these exercises.
00:15I'll go to the Files panel, and I'll select the Site header.
00:19This is the item in the tree at the very top that shows the site name.
00:23And then you can either right-click on that item and choose Put, or you can
00:28click the up arrow in the toolbar, which means the same thing.
00:32When I click the button, I'm asked whether I want to put the entire site
00:35onto the remote server.
00:37I'll click OK, and I'll see that the files are copied very quickly.
00:42Now, I'm working with an FTP Server on my local computer, and so the copying
00:46is incredibly fast.
00:47When you're working with an actual remote site, you'll see that it takes quite a bit longer.
00:53Now, to make sure that files have been copied correctly, I'll go to the Files
00:58panel and choose Remote Server, and I see that all of the files and directories
01:02have been successfully copied over.
01:04Then I'll go back to the Local View.
01:07You can also use synchronization.
01:09When you synchronize, Dreamweaver checks the file names and time-date stamps
01:14for the files on the client and on the server, and then tells you which files have to be copied.
01:20I'll demonstrate this with the file phpinfo.php.
01:24I'll look at the code for this file.
01:27It sets a time zone, indicates the current time, and then outputs the result of
01:32the phpinfo function.
01:36I'm looking at the file in my testing site, which is located in the dwwithphp folder.
01:42I'll change this URL to indicate that I want to look at the remote site, and
01:47I'll see that the output is exactly the same.
01:50It's two different copies of the page:
01:52one stored on the testing server, one stored on the remote server.
01:57Now I'm going to make a change to the file.
02:00I'll go to the code right before phpinfo, and I'll type echo and then an h1 tag
02:07wrapped in quotes, and then using a period to concatenate, I'll append PHP Info,
02:14another period, and then in quotes a closing h1 tag.
02:21I'll save my changes and run the page in the browser using the Preview button,
02:25and I'll see the new h1 tag appear, and I'll note that I'm still working in
02:30the testing server.
02:32I'll change to the remote server, and I'll see that that version doesn't have the change.
02:37Now, I'll go back to Dreamweaver.
02:39To synchronize, I'm going to right-click on the site heading and
02:43choose Synchronize.
02:45You can also click on a button on the toolbar.
02:46The Synchronize Files dialog box asks me which direction I want to synchronize in.
02:52The options are to put newer files to remote, get newer files from remote, or to
02:58do both Get and Put operations at the same time.
03:01I'll choose the default, putting newer files to remote.
03:05I'll Preview, and after a very quick moment, Dreamweaver indicates that the
03:09phpinfo.php file is needed.
03:13There is another file here that it picked up that I don't want to put onto the site.
03:17I'll click that, and then click the Ignore button, which looks like a little stop sign.
03:22I'll click OK, and the file is very quickly copied to the remote site.
03:27I'll switch back to the browser, which is showing the PHP Info page on the
03:32remote site, and I'll just refresh, and I'll show that the change appears.
03:38I now see the new text that I had changed in the local site, because it has been
03:42synchronized to the remote site.
03:46When you use the synchronization function, you can either do it for the entire
03:49site, as I showed here, or you can do it for one folder at a time, or one file at a time.
03:56Just select the file, folders, or site that you want to synchronize, and then
04:00start the synchronization function.
04:05It's also worth noting that in your Exercise Files directory, you'll have a new
04:09set of files, called dwsync.xml.
04:13This file appears in the notes subfolder of every physical folder of your site.
04:19It's an XML file that tracks all of the files in your site, and includes
04:23information about the local copy, the remote copy, and the date-time stamps
04:29expressed as integer values, indicating which version is which, and how they might differ.
04:35The dwsync.xml file is used by Dreamweaver to handle the
04:39synchronization process.
04:41If you have any troubles with synchronization, you can simply wipe out the
04:46dwsync.xml files from your entire structure.
04:49Remember, there are multiple versions of dwsync.xml, one in the notes subfolder
04:54of every site folder.
04:57After you've gotten rid of those XML files, re-put everything onto your remote
05:01site, and the synchronization files will be recreated for you.
05:06So that's a look at how to work with the remote site using the FTP
05:10capabilities of Dreamweaver CS5.
05:13You can put files, folders, or the entire site onto the remote site, or you can
05:18synchronize, automatically detecting changes in the local files, and copying
05:24only those files to the remote site as needed.
Collapse this transcript
Exporting the MySQL database to a script
00:00In addition to posting your php files on your web site, you also need to create
00:05a copy of your database on your remote server.
00:08The particular installation of MySQL will depend on how you're using your
00:12server on the remote site.
00:14In many cases, your database is created for you by your Internet Service
00:18Provider or by your web site manager, but it's up to you to create an SQL script
00:24that you can run to re-create your database structure remotely.
00:28In this video, I'll show you how to create the script using phpMyAdmin.
00:32If you're working with WampServer on Windows, you can open up phpMyAdmin from
00:36the admin menu. And if you're working on MAMP on Mac OS X, go to the MAMP
00:41homepage and then click phpMyAdmin. From there, click into your database.
00:47My database is named explorecalifornia and then click Export at the top of the table list.
00:54In the Export Screen, you're asked which tables you want to export.
00:57I'm going to select all of the tables. Then there're some options you need to look at.
01:02You'll want to output the SQL format - that's the default - and then under Options,
01:08click the option to add a drop table view, and so on.
01:13This means that when you run the script, if a particular table structure already
01:16exists, it will be replaced.
01:19There are other options that you might want to include.
01:21For example, if you want a fresh, clean database, you can uncheck the Data
01:26option, and then you'll only get the structure, or you can add the data option
01:31and then go into the resulting SQL script and make any changes you need to.
01:36At the bottom of the screen, check Save As file, and you'll be prompted when the
01:40file is supposed to be saved. Click Go.
01:44Now, depending on which browser you're working in, you'll either see this
01:48dialog, or you'll see that the file is automatically saved.
01:52I'm going to select Save File and click OK.
01:56In Firefox, the file is automatically created in your downloads folder.
02:00If you're working with Internet Explorer on Windows, you'll be prompted for the
02:04location where you want to save the file.
02:07Working in Firefox, I'll right-click on the file reference, and choose Open
02:11Containing Folder, and then from there, I'll right-click and open the file.
02:16I'm using TextPad, but you can use whatever text editor you want.
02:21The file will include all of the data structure and actual data.
02:25If you don't want to include actual data in a table, there are two steps to follow.
02:30First of all, go to the insert statements, under the dumping data comment, and delete them.
02:37And then, go back to the table structure and change the auto increment value
02:41from whatever it's set at to a value of 1, and that means when the first record
02:46is inserted, the primary key value will be 1.
02:49You can also make changes such as the database engine, which is done on a per-
02:52table basis and any other changes that you want to make.
02:56Once you've created the SQL file, save it, and you'll be ready to move on to
03:01the next step, importing the file into your remote database, which I'll
03:06describe in another video.
Collapse this transcript
Importing the MySQL database on a remote server
00:00When you generate a script from phpMyAdmin, it can be executed either in another
00:05copy of phpMyAdmin or in any other user interface for MySQL.
00:11In most cases, if you're working with an Internet Service Provider, you'll have
00:15a copy of phpMyAdmin that you can use.
00:18If you're working with an independent copy of MySQL, you can download a copy of
00:22the MySQL user interface tools from the MySQL web site. The script should work
00:27in that software as well.
00:30Before you run the script on your remote server, go into the script and make
00:34any changes you need.
00:35For example, I'm going to change the name of my database from explorecalifornia,
00:41the local name, to exploreremote.
00:46Changing this comment doesn't have any actual effect on the database itself.
00:50You'll still create the database manually in phpMyAdmin, but then you'll run the
00:55script in phpMyAdmin against the new database.
00:58I'll save the changes and close the text editor, and then I'll go to phpMyAdmin.
01:06Within phpMyAdmin, I'll create a new database, and I'll name it exploreremote.
01:13I'll click Create, and then I'll click the Import button, and I'll navigate to
01:18the location of MySQL file, which I've placed in the exercise files area, under
01:24the chapter for this folder, 09_deployremote.
01:28And then the name of the file is explorecalifornia.sql.
01:33I'll select the file and click Go.
01:36My new database now has the structure and wherever I've left the insert
01:40statements in the actual data.
01:42For example, the admin table still has the same username and password in its one
01:48and only record, but the explorers table is empty - that is, there is no data in
01:53it, because in the SQL file, I removed all the insert statements.
01:58So, whether you move data in addition to the structure is completely up to you.
02:03For some tables, you might want to include them in the script, and for others, you
02:06might want to use a completely fresh copy of the table.
02:10So you've reproduced your database, structure, and data on the remote site, and
02:15now you're ready to work with it from your remote web site, and I'll show you
02:19how to configure your connections file to do that in another video.
Collapse this transcript
Configuring the site for the remote database
00:00Once you have deployed your database to a remote server, you can configure your
00:04Dreamweaver site so that when it's running locally, it's talking to the local
00:08database, and when it's working on the remote site, it's working with the remote database.
00:13To do this, you'll have to make some customizations to your connections file.
00:18In my web site, it's called explorecalifornia.php, and these files are always
00:23located in the Connections folder, under the site root.
00:26In the connections file, there are four variables being set:
00:30the hostname, the database name, the username, and the password.
00:36These settings currently are for the local database.
00:39Using a little bit of PHP conditional code, you can detect where you are running,
00:43and set the variables accordingly.
00:45I will start in this demonstration by doing little bit of debugging and showing
00:50you some values that you can inspect to find out where you are running.
00:53I will use an echo command, and I will output to values concatenated together.
00:59The first is $_SERVER HTTP HOST.
01:04This returns the name of the domain that's accepting and processing the request.
01:09Then I will put in a dot for concatenation, and then I will output
01:13$_SERVER bracket REQUEST_URI.
01:19This is the full name of the page, as it's known to the browser.
01:23Now I will save the changes and run the page in the browser and show you that it
01:28returns the name of the domain, in this case local host, and then the full URI,
01:35or Uniform Resource Identifier.
01:37That includes all of the folders and the file name that's being requested.
01:42In this case, my local server is running in the folder dwwithphp.
01:47Now let's see what happens when I am working on the remote server.
01:50I will go back to Dreamweaver, and I will go to the Files panel to the
01:55Connections folder, and I will put this file onto my server.
01:58Then I will go back to the browser, and I will replace the name with the
02:02folder that I am using as my local server with the name of folder I am using
02:06as the remote server, remote, and I will see that the same file returns a value of remote.
02:13So for this demonstration, I am going to look for the word "remote," and if I
02:16find it, I will determine that I am on a remote server.
02:20When you are working with an actual remote site, look for your domain name, or
02:24your IP Address, because if that value is a part of this string, that tells you
02:29are working on the remote site.
02:32Here is the PHP code I'll use to do the detection.
02:34I will change this line of code, so that instead of echoing this value, I will
02:39save this value as a variable.
02:40I will call it requesturi.
02:47Then I will create a variable called pos, standing for position, and I will get
02:52the value of that variable by calling a function called strpos.
02:57The strpos function looks for a substring within a string.
03:02In the syntax example, you will see that PHP refers to this as finding a
03:06needle in a haystack.
03:08So the first value I will pass in is the haystack,
03:11my variable requesturi, and then the second value I will pass in is remote and
03:18again, if you are working within actual remote site, it might be
03:21mycompany.com, the domain name.
03:25The strpos function returns the numeric position of the string that it finds.
03:30Or if it doesn't find anything, it returns a blank value.
03:33You can determine whether the string was found in the requesturi by asking
03:38whether to pos variable returns true or false.
03:42So I am going add an if clause.
03:44I will create the if statement with a pair of parentheses and an else statement,
03:50also with a pair of parentheses.
03:51Then I will take the four variables that are being set.
03:55I will cut them to the clipboard, and I will paste them twice into both the if
04:00clause and into the else clause.
04:04Now I will apply a condition.
04:07For the if clause, I will place the cursor between the parentheses, and I will
04:11simply type in the name of the variable, pos.
04:14This expression will return true if the value was found and false if it
04:18wasn't. So the first condition is for the remote site, not for the local, and I
04:24am going to change the name of the database from explorecalifornia to
04:28exploreremote. And again, if you are working on an actual remote site, you would
04:33change all of these values:
04:35the hostname, the database name, the username, and the password.
04:39In my case, all of the values are the same except for the database itself.
04:42I will save my changes, and I will go to my site header, and I will synchronize.
04:50This time I am going to click the Synchronize button in the toolbar, just to
04:53show you that that's an available workflow.
04:55I will preview files that need to be put onto the remote server, and I will see
05:00that my connections file is eligible.
05:02I will click OK, and that places the new version of the file on the remote server.
05:10Now I am going to open the file in the Explorers folder, explorerlist.php.
05:15You may remember that the difference that I created between the local database
05:19and the remote database is that I removed all the data from the explorers table.
05:24So I will open explorerlist.php, and I will run it in the browser.
05:33So right now, I am looking at the login form for the local site.
05:36I will login with User Name explorerone and the Password, which is simply
05:42password, and when I look at the version of the list page on the local site, I
05:48see all of the data.
05:51Now I will go to the web address in the browser, and I will change from the
05:55local site, dwwithphp, to the remote site in the remote folder.
06:00If you are prompted to log in again, do so.
06:03But then you should see the version of the page on the remote site that shows
06:07that there is nothing in the database, that is that the explorers table is empty.
06:11And that verifies that you are looking at the version of the database that's
06:15targeted for the remote site.
06:18When you customize your connections file, you should be aware that it may cause
06:23some problems for Dreamweaver.
06:24For example, if I now go to the Databases panel and refresh, depending on the
06:29state of your setup, you may or may not be able to see the list of tables, and
06:34you may or may not be able to add new server behaviors.
06:37If you have any trouble with this, I recommend keeping a couple of different
06:41copies of your connections file around, and just rename them as needed when you
06:45are doing your development work.
06:47In this case, all of my development work is complete, and I am simply deploying
06:52my finished PHP site to my remote server, and if I need to make any bug fixes or
06:57add simple features to the site later on, I will be able to easily do so using
07:02this connections file that's been customized to work with both the local and
07:06the remote database.
Collapse this transcript
Conclusion
Final thoughts
00:00Thanks for sitting with me through this video series; Dreamweaver with PHP and MySQL.
00:06In this series, I showed you how to use Dreamweaver to build a dynamic web site
00:11that works with the PHP application server and the MySQL database server.
00:17I described how to structure and populate a database, how to query and display
00:22dynamic data in your web pages, how to manage your data with data entry forms,
00:27and how to create a secure user authentication model.
00:31I also showed how to integrate common PHP-based libraries, such as the Zend
00:37Framework with your dynamic pages.
00:40You now have the tools to design, build, and deploy your own dynamic web sites,
00:45using Dreamweaver with PHP and MySQL.
00:49Thanks again for watching and listening!
Collapse this transcript


Suggested courses to watch next:

PHP with MySQL Beyond the Basics (10h 27m)
Kevin Skoglund

MySQL Essential Training (2h 46m)
Bill Weinman


Dreamweaver CS5 Essential Training (15h 22m)
James Williamson


Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 104,141 instructional videos.

get started learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 2,025 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.

preview image of new course page

Try our new course pages

Explore our redesigned course pages, and tell us about your experience.

If you want to switch back to the old view, change your site preferences from the my account menu.

Try the new pages No, thanks

site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

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.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

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

   
submit Lightbox submit clicked