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 created a data entry form using your own custom HTML and Cascading Style Sheets, and prepared your database table to receive inserts, you can then apply a server behavior to the form. The server behavior creates all of the PHP code you need to collect the data from the form and send it to the server. I am working in the file explorers/explorerinsert2.php. This version of the form already has all of the data validation I need. I will show the form in the browser and show you its behavior.
When I click the Submit button, I get validation messages on all of the relevant text fields and also on the State Select control. I'll go back to Dreamweaver and then open the Server Behaviors panel. If you don't see Server Behaviors on the right, as it is in my setup, you can go to the menu and choose Window > Server Behaviors. In the Server Behaviors panel, I'll click the Plus button and then choose Insert Record. In the Insert Record wizard, I am asked for the form that I'm going to collect data from.
There is only one form in this page, and it has a name of explorerForm; the database connection, and again there is only one explorecalifornia; and then the table into which I want to insert data. I'll choose the explorers table. Just as when using the Insert Record wizard, Dreamweaver detects the database structure and figures out dynamically what data types will be used in formatting data to add to the database. Most of these columns are simple text columns, but the DOB is a date column in the database table, and so it's going to be formatted as a date in my PHP code.
Also, just like the wizard, I am asked which page I want to browse to after the Insert operation is done. I will click the Browse button. I'll make sure I am in the explorers folder in my current site, and I'll choose explorerlist.php and click OK. In a previous video, I described one issue that happens with the generated PHP code from Dreamweaver. When you're working with date values, Dreamweaver isn't very good at formatting the date as needed for MySQL, and I showed you in that video how to write a little bit of custom PHP code that would collect the data correctly and format it for MySQL.
Now I am going to show you how to create that code in a reusable form. In the _includes folder, I've created a file named formfunction.php. The folder is _includes under the site root, and I have made a copy of two parts of the PHP code for my previous exercise. I have a require_once command that includes the Zend library's date class, and I have also included a copy of the GetSQLValueString function, and in the case for the date type, I've added the custom code that retrieves the data expecting the format that the users has to type in: month, day and year, and reformated it as required by MySQL.
Here is how I will use that file in the generated PHP code in my data entry form. I will return to the file explorerinsert2.php and go to Code View, and up at the top, after the require_once command for the connection, I'll add another PHP code block and another require_once command. And I'll include that file formfunctions.php, using the relative address ../_includes/formfunctions.php.
I'll close the name of the file, the require_once command, add the semicolon and close the PHP code block. Now in my newly generated code in this file, I have another version of the GetSQLValueString function. I don't need to remove that function definition because it's wrapped inside this conditional block, asking whether the function already exists. Because I've now included the version from the formfunctions file, this definition will be ignored, and the version that has the correct date formatting will be used at runtime.
I'm ready to test my form. I'll save my changes and run the page in an external browser. If you're prompted to copy files to the server, say yes. I'll type in some names. I'll type in a date of birth using the required date format. I'll use 6/23/2009. I'll add an e-mail address. I'll ignore the Address and City this time, because the form doesn't require them to be entered, and I have set up my database now so that they can be left blank, and I will choose a State.
Then I will click Submit, and I'll be taken back to my list page, and I'll show you that the date was entered correctly because of the revised and customized date formatting in my PHP code that was included from that separate file. So in this video, I have shown you how to use the server behavior for inserting a record and apply it to an existing data entry form. I've also shown you how to handle the special case of date formatting to allow the user to type in a date value in whatever format you choose.
You simply need to match the format of the date as expected when you create your Zend date object and match it to the validation rule in your form. Then you format the date correctly, as expected by MySQL. The result is a very simple data entry form that collects the data from the user, formats it correctly, and then sends it to your MySQL database.
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.