Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Dreamweaver supports a variety of features that help you generate PHP code for retrieving, inserting, updating, and deleting data in a MySQL database. In all of the videos of this chapter, I'll work in a folder of the exercise files area named 07_managingdata. If you're working with the exercise files, set your site definition to point to this as the root folder. I'm going to start by showing you how to use one of the data wizards that's included with Dreamweaver CS5.
These wizards are very easy to use and work very quickly, but they may not always be modifiable for your own site. First, I'm going to check to make sure that my database connection is set up correctly. I'll open any PHP file. I'll select index.php from the Home folder. Then I'll go to the Databases panel, and I'll double-click explorecalifornia. If you're working on Windows with WampServer, the settings should already be correct. If you're working with MAMP on Mac OS X, click into the Password entry and type "root," and then regardless of which operating system you're working on, click Test.
If you're working on Windows, you might see this message. If so, click OK, and then click Test again. And then regardless of whether you're working on Mac or Windows, you should see the message that the connection was made successfully. Click OK and click OK again. Now you're ready to create a web page using one of the data wizards. Create a new page based on the page type PHP. Set the Layout to none and click Create, and then save the file into your site's Home folder, and name it insertfromwizard.php, and click Save.
Then look at the page in Design View. I'm going to add a data entry form that primarily uses text boxes, but has one pulldown list, or select control, that uses data from the states table of my database. So before using the wizard, I'll add a recordset for that table. I'll go to the Bindings panel and click Plus and select Recordset. If you see the advanced Recordset dialog appear, click the Simple button, and you should see this display. Give the new recordset a name of rsStates.
The Connection should be set to explorecalifornia, and then set the Table to states. You'll be selecting both columns of the states Table: stateId and stateName. Set the Sort value to stateName, click Test, and it should show you a list of the first 25 records from the states table. Click OK and click OK again. Now you're ready to use a wizard to add a data entry form. Go to the menu and choose Insert, choose Data Objects, and you'll see three items named Insert Record, Update Record, and Delete Record.
Choose Insert Record and then Record Insertion Form Wizard. Once again, you're asked which table you want to work with. Choose explorers. Next you're asked which page you want to navigate to after the data entry form is finished. Click the Browse button, and make sure that you're in the correct folder, starting from 07_managingdata. From there, go down to the explorers folder and choose explorerlist.php.
You'll see that Dreamweaver sets that up as a relative address. Because your form file is in the root folder, you'll be navigating to explorerlist.php in the explorers folder. Now you're asked which form fields you want to display. You don't want to show the primary key column. MySQL will add the value for that. So click explorerId and then click minus, and that removes that column from the data entry form. Next, scroll down a bit and click on the state column.
Display that as a menu, rather than a text field. Then click Menu Properties. I'm going to display the values from the database query, the recordset that I already added to this page. So I'll choose From database, and I'll see the recordset rsStates appear, it's the only recordset in this page, and I'll indicate that I want to get the labels from the stateName column, and I'll click OK, and that takes me back to the Record Insertion Form Wizard, and I'll click OK again.
There is my data entry form. I'm going to test the form. I'll save the file and then view it in a browser. If you see the dialogs asking whether you want to copy the files to the server, indicate that you do. Once the form opens, make sure you type values into every text field. I'll set the FirstName as Joey, the LastName as Adams. Make sure that you enter a valid date for the Dob, or date of birth. I'll enter a value of 2007.
You can add any e-mail address, and then any address value, and any city. Set the Zipcode, UserName, and Password to any values you want. Then click Insert record. After the data entry form functionality is complete, you'll see that the new data is listed in the explorerlist page, but you might notice an issue, that the Birthdate is displayed in an odd way. I entered a valid date, but it's being displayed as a value of 11/30/99.
To investigate that, I'll go to phpMyAdmin and look directly at the database contents. I'll go to the explorecalifornia database, to the explorers table, and I'll show you that all the values that I entered into the form are in the database, but that the Dob was entered incorrectly. One of the challenges with using Dreamweaver's automatic PHP code-generation is that it isn't entirely up to date with the requirements of the MySQL database. So in the next video, I'm going to show you how to correct this issue by writing a little bit of custom PHP code and customizing the code that's generated by Dreamweaver.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98268 Viewers
80 Video lessons · 141407 Viewers
59 Video lessons · 59771 Viewers
52 Video lessons · 72980 Viewers
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.