HomePHP Page 8 - Building PHP Applications With Macromedia Dreamweaver MX
In And Out - PHP
Looking for a RAD tool to help you quickly and efficiently develop PHP-based Web applications? Or just new to PHP and MySQL in general? You might want to spend some time with Dreamweaver MX, Macromedia's latest revision of their venerable HTML editor, which comes with some nifty new ideas designed to minimize hand-coding of PHP scripts.
OK, so that took care of displaying the records - now how about inserting and deleting records?
First, use the Dreamweaver editor to create an HTML form that maps to the columns of the "user" table.
Once the form has been prepared, apply the "Insert Record" server behavior, and you'll see a dialog box like this:
This dialog box makes it very easy to map form fields to the table in which data is to be inserted. Once you select the appropriate database connection and table, the fields of the table are displayed; these fields can be mapped to specific fields in the form via the "Value" drop-down list. Dreamweaver takes care of writing the SQL query needed to insert the data entered by the user in each field into the appropriate column in the table.
After you've finished mapping form fields to table columns, remember to specify the URL to which the browser should be redirected once the data has been successfully inserted into the database.
Once you're done, save the PHP script and access it via your browser. You should see the HTML form you created:
Enter some values and submit the form. The code generated by Dreamweaver MX will insert the values into the "user" table and then redirect the browser to the URL selected...all without the developer writing a single line of code!
It's just as simple to delete records - create a new PHP script and use the "Delete Record" server behavior. You'll see the following dialog box, which asks you to specify the variables that the script should use when identifying which record to delete.
As you can see, in the example above, I've told Dreamweaver to look for the "id" variable in the URL string, and to delete the record corresponding to that ID in the "user" table. Save the script (I'll assume it's called "delete.php"), and access it via your browser (remember to add the "id" variable-value pair to the URL string, like thus: http://your.server/delete.php?id=15), and the record corresponding to the ID provided should get deleted from the database.
Obviously, it's pretty easy to now link the three scripts above with each other, so as to build a primitive, yet fully-functional, user administration module (in case you're wondering, yes, Dreamweaver also comes with an "Update Record" behavior - I'll leave that to you to experiment with.)