Start learning with our library of video tutorials taught by experts. Get started
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.
In a previous video, I described how to use the Record Insertion Wizard to create a data entry form that would collect information from the user and add it to the MySQL database, but I showed that there is a challenge with working with dates. That's because the code that's created by Dreamweaver doesn't do an adequate job of formatting dates as they're expected by MySQL. I'm working in the file, insertfromwizard2.php, in the root folder of the current site. Here is the problem code.
It starts with a case statement, and it's within a function named GetSQLValueString. The case statement for dates assumes that the user has typed in a value in a format that's acceptable to MySQL. Clearly, that isn't always the case. So I'm going to replace this string with a little bit more complex PHP code that uses the Zend_Date class that I've demonstrated in previous videos. I'll go to the top of the file and add a require_once command to incorporate the Zend_Date class into my page.
I'll add a PHP code block and then the require_once command and then the Zend/Date.php file. Make sure you complete the PHP code block at this point. Then go down to the offending code. Here is the line of code I need to replace. I'm going to select and delete it, and then I'll replace it with a complete if else statement. I'll start by creating the entire conditional logic, with if and a pair of parentheses, and a pair of braces, and then an else, and another pair of braces.
Then I'll go back to the parentheses after the if and add the condition I'm examining. I'm asking the question, did the user type in a value at all? I'll enter $theValue and then the equality operator, double equals, and then quote, quote, meaning blank string, Dreamweaver's syntax checking now shows me that there are no syntax errors. I now have a complete conditional block. If the value that the user typed in is blank, I'm going to set it to a value of null, using a very simple assignment statement of theValue =, and then the word "NULL" in uppercase.
In the else clause, I'm going to assume that the user typed in a value formatted as a date, in the format month/day/year, and eventually I'll add validation rules into my data entry form that ensures the value is typed in in this format. I'll take the value the user typed in and turn it into an instance of the Zend_Date class. I'll create a variable called zendDate, and I'll create it from a new instance of the Zend_Date class, and the first value that I'll pass in is the value that the user typed in in the form, theValue.
The second part is the format that I'm expecting. I'll type that in as a literal string, using quote, an uppercase M for the Month, then a slash, then a lowercase d for the date as a number, then a slash, and then four ys for the year. I now have an instance of the Zend_Date class, representing the value the user typed in. I can format it any way I want. I'll create a new line of code, and I'll replace the variable of theValue using a single quote, a formatted date, and another single quote.
I'll start with a single quote wrapped in double quotes, then a period, indicating that I'm going to concatenate, or append another value. Then I'll call the zendDate objects to string method. I'll pass in a formatting string, indicating the formatting that's expected by MySQL. In double quotes, it will look like this: yyyy for a four-digit year, then a dash, then MM in uppercase, then a dash, then dd in lowercase for the day, and finally, I'll concatenate another single quote at the end.
So now I have a formatted date string wrapped in single quotes. That's the extent of the changes to my data entry form's code. I'll save my changes and then run the form in the browser. I'll type in some values. The FirstName will be Mikey, then Jones. Make sure that you type in a valid date of birth in the common format used in the United States. I'll type in a value of 5/12/1963, type in any e-mail address, and then type in any other values you like in the rest of the form.
Because of certain restrictions in the database structure, you must type in values into all of these form controls. Once you've typed in all of the values, click Insert record. You should go directly to the explorerlist page and see that this time the date was entered correctly. Here is my new record, and the date is displayed, formatted by the Zend_Date class. So that's a look at how to customize your data entry forms after Dreamweaver has generated the code.
This strategy can be used both for code that's generated by the Record Insertion Wizard and for code that's added to existing forms, which I'll show you how to build in another video.
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.