Viewers: in countries Watching now:
Join author David Gassner as he describes how to add dynamic data to a PHP-enabled web site in Adobe Dreamweaver. This intermediate course shows how to plan and create a MySQL database, define a PHP-enabled site in Dreamweaver, connect the site to the database, and manage and present dynamic data. David also explores Dreamweaver features such as PHP custom class introspection and site-specific code hinting as well as the differences between the CS5 and CS6 versions of the software.
This course was updated on 6/12/2012.
Once you've prepared you data entry form, you can apply a server behavior to it, to collect the data from the form, and then update a record in the server-side database table. For this exercise, I'll use the file explorerupdate2.php in the explorers folder of the site root. This page is designed to retrieve a single record from the database table and display it in the browser. The user can make changes to the data and click Submit, and the data should then be sent to the server. There is a problem with this form, though.
When I click the Submit button, I get an Invalid Format message on the date, and that's because this data entry form is designed to validate the date and look for it in the format of month/day/year. So we have to reformat that value before we present it in the form. I'll close the browser and return to Dreamweaver, and go to Code view. Now, in the previous exercise, I showed you a file that's a part of the _includes folder, named formfunctions.php.
This file has a require_once that includes the Date class from Zend framework. And then down at the bottom it has a function we're now going to use, called dbDateToFormDate. It accepts a single variable, named formDate, casts it in a Zend_Date object, and then reformats it and returns it in the form of month/day/4-digit year. I am going to use this function so I can format the value correctly. I'll use this function in my form page.
I'll go to the form and scroll all the way up to the top, I'll place the cursor after the PHP require_once command for the database connection, and I'll add another PHP code block. Within the code block I'll add a require _once function call, and I'll call the file ../_includes/formfunctions.php. So now, the two functions that are in that file, the correct version of GetSQLValueString and the function that I am going to use to format the date in the form, are both available to this page.
Now I'll go to Design View, and I'll go to the Date of Birth field. I'll click it and then go to Code View, and this helps me find the code I am looking for in the code. I'll go to fullscreen and then in order to present the date in the correct format, I'll go to the PHP command that's outputting the value in the form control. This is the expression that's being output now, the DOB column in its raw form. I am going to wrap that expression inside my custom function that's in the included file.
It looks like this. I'll start with dbdate. Then I'll press Ctrl+Spacebar and using Dreamweaver's code hinting, I'll select the correct function name, dbDateToFormDate. Then I'll place the cursor after the expression - that retrieves the data from the database - and I'll add a closing parenthesis. I should now see that there are no syntax errors in my PHP code. I'll save and run the page in the browser. And now the date is formatted as the form expects it to be and also as the function expects it to be in order to cast it to MySQL.
Now I am ready to apply the server behavior. I'll go back to Dreamweaver to Design View, and I'll look at my panels by pressing the F4 key. I'll go to Server Behaviors, I'll click the Plus button, and I'll choose Update Record. I'll check the values in the first two items. I am submitting the values from the only form in the page, explorer form, and I am using the explorecalifornia database connection. I'll pull down the list of tables and choose explorers, as before, and then I'll check all of the mappings of form controls to database table columns.
For example, the explorerId form control, the hidden control, is used to select the record to update, and all of the other table columns get their values from various controls. Dreamweaver matches this all up automatically because I have matched the names of my form controls to the names of the database columns. If you haven't matched them in the same way, you can still use the server behavior by manually matching the columns to your form controls. As with other server behaviors and wizards that I've shown in this chapter, you can also tell Dreamweaver to set up code to go back to a particular page after the update operation is done.
I'll click Browse, and I'll choose explorerlist.php and click OK. I am ready to test the Update feature. I'll save my changes, and I'll run the page, and I see that the First Name is Jackie and the Last Name is Smith. I am going to change the Last Name from Smith to Jones, and I'll change the Date of Birth from 7/10/1985 to 7/10/1981. I'll change the Email address from jackiesmith to jackiejones, and you can make other changes if you like.
I'll click Submit, and I'll see that I go back to the explorerlist page, and the Jackie Jones record has been correctly updated. So that's a look at how to prepare a data entry form for use with an update operation and how to apply the Dreamweaver update record server behavior to minimize the amount of hand coding you have to do of PHP, and also how to integrate features of the Zend framework to make it easier to format your date values.
Find answers to the most frequently asked questions about Dreamweaver with PHP and MySQL .
Here are the FAQs that matched your search "" :
<?php include('../ZendFramework/library/Zend/Date.php'); ?
<?php echo $_SERVER['DOCUMENT_ROOT']; ?
You can then programmatically modify the include_path variable at runtime with the set_include_path() function. For example, if your physical root folder is /home/myroot, the code might look like this:
<?phpset_include_path('.' . PATH_SEPARATOR .'/home/myroot/ZendFramework/library/Zend');include('Date.php');?
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.