Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Just as with inserting data into a database, you can create a data entry form to update data using Dreamweaver's update record server behavior. Before you use the server behavior though, you need to prepare the form to display data from a single record that the user wants to update. I'll be working in the file explorerupdate. php, in the Explorers folder of my site root. The first step is to add a binding, or recordset to the form, to retrieve a single record from the database table. I'll go to the Bindings panel and click plus and choose Recordset or Query.
I'll give my recordset a name of rsExplorer. Notice I am using the singular version of Explorer, rather than the plural version, because I am only going to retrieve the single record, filtered by the primary key of the table. Then I'll choose the Explorers table. I'll click Selected, and then holding down Ctrl on Windows or Command on Mac, I'll select only the fields that I want to display in the form: the explorerId, firstName, lastName, dob, email, address, and make sure that I've also selected the state.
I am going to filter. I'll pull down the list of available columns and choose the primary key column for this table, explorerId. The default SQL statement will be designed to retrieve a single record, filtered on the primary key column, explorerId, looking for a URL parameter, known in PHP as a Get variable, and by default, the name of the variable will be the same as the column name;, explorerId. I'll click the Test button and provide a test value for the primary key.
I'll provide a value of 1. I'll click OK, and I'll see that I've retrieved all of the columns I need to fill in my data entry form. I'll click OK, and click OK again, and that adds the SQL statement or recordset to the form page. I'll add information to the form controls to cause them to display the values from the retrieved record. I'll start with the First Name column. I'll click on the text field and then go down to the Properties panel.
I'll click the Bind to Dynamic Source button, the lightning bolt for that column, and I'll choose the matching column in the database, the First Name column in the rsExplorer Recordset, and click OK. I'll do the same thing for each of the other text fields: The Last Name, and Date of Birth, the Email address, the Address, and the City.
If for any reason I've forgotten one of the columns, as I have here, I can cancel out, go back to the Bindings panel, double-click on the recordset to reopen it, and then, holding down the Ctrl key, I can select the column that I missed. Make sure you're holding down Ctrl on Windows or Command on Mac when you do the click; otherwise, you will deselect everything else. I'll click OK, and that updates the recordset in the page. Go back to the City field, and once again click the Bind to Dynamic Source button, and now I should be able to choose the City column.
You can also set the current value for a select control. I'll click on the State select control, and I'll go to the Properties panel and click Dynamic. And then for set value equal to, I'll click the lightning bolt button, and I'll choose the matching column, state. I'll click OK and click OK again, and now my data entry form will match whatever value is passed to it when the file opens. There is one more column though, that you need to account for. When you're working with an HTML data entry form for managing data, you have to pass the primary key value of the current record from the form to the action, that is to the page that's going to process the request by the user.
You do this with a hidden data entry form field. I'll click right after the Submit button in the form, then I'll switch to Code View, and I'll check the location of the cursor. You need to make sure that the cursor is inside the form. A hidden field won't affect the appearance of the form at all, but if it's placed say outside the form, where I have placed the cursor now, the value won't be passed from form to action. So I'll place the cursor right before the ending form tag. Then I'll go to the Insert panel and choose Forms, and I'll add a hidden field.
Because I'm in Code View, I get the Tag Editor Dialog box. I'll click OK, then go back to Design View and show you that the hidden form field is displayed by this icon in the upper-right. Again, don't worry about its visual appearance, or its placement on the screen; because it's hidden, it will be invisible to the user. I'll select the Hidden Field that I created, then I'll click into the Properties panel, and I'll assign the name matching the name of the database column for the primary key, explorerId.
Don't worry about the case. It doesn't matter whether it's uppercase, lowercase, or mixed case. It just has to match the name of the database column in the table. Then I'll go to the value, and just as I did with the text fields, I'll click the Dynamic button, and I'll match this controls value to the explorerId column in the recordset, and I'll click OK. If you save and test the form at this point, it won't be quite right. I'll click and preview, and you'll see that the form is displayed with nothing in it. Here is why.
Let's take a look at the generated code. I'll go to the Code View, and then I'm going to press Ctrl+F on Windows or Command+F on Mac, and I am going to search for rsExplorer. I'll click Find Next, and you'll see that you may not get to the actual definition of the recordset. But if you click Find All, you'll get a listing of all references, and here is the code I am looking for. There is a variable that's generated by Dreamweaver called colname_rsExplorer, which is set to a default of -1.
In the Search panel, I'll double-click on that bit of code, and that takes me to line 40 in my page, where the value is being set. This is the default primary key value for the record that will be displayed in the form. Because I am not connecting this page to the rest of my data entry or data management system yet, I'm just going to change this value so that I am displaying the data from the first record in the table. I'll change the default value of the primary key column from -1, which means I am not retrieving anything, to 1, which means I am retrieving the record with that primary key value.
I'll save my change, and then I'll preview the page in the browser, and now I see the data from the record with a primary key value of 1. There is one more step to follow, which is updating the date format, and I'll show you how to do that in another video.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 81227 Viewers
80 Video lessons · 133185 Viewers
52 Video lessons · 66564 Viewers
59 Video lessons · 52381 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.
Your file was successfully uploaded.