Frost on your window, circle more

October 5th, 2004, By Duncan Gough

// More on mod_mysql

Having thought about it more I realise that I’m attacking the problem from the wrong direction - I don’t want mod_mysql to take away from all the scripting and leave me with just a couple of hooks for doing my own thing when some scripting is required. What I really *need* is for mod_mysql to take control only when I want it to. What do I mean by that? Well, I want mod_myslq to work just like mod_rewrite does.

That is, I want to drop in a .htaccess file for any directory that’s full of boring forms that I don’t want to write code for. mod_mysql can be intelligent enough to match up the form fields with the relevant database tables if I make sure that the forms are labelled and identified accordingly.

That way, I can have my ’site and use all the scripting I want, but when it comes to form handling, I can let mod_mysql take control. Having thought about it, the form handling I loathe the most is normally tied up in user registration and profiles. Which, thanks to my attempts at a RESTful website layout, means that I only want mod_mysql to take control in these folders:

http://www.example.com/register/
http://www.example.com/profile/

So, all I need do is setup a .htaccess file in both of those folders and tell mod_mysql what I want it to do, eg:

<Directory /var/www/html/register/>
  <IfModule mod_mysql.c>
    TableName Users
    FormSuccess /var/www/html/register/success.html
    FormError /var/www/html/register/error.html
  </IfModule>
</Directory>

All this does is tell mod_mysql to handle the form in http://www.example.com/register/ and validate the submitted contents of the form against the database table ‘User’. If everything matches up, it can update/edit/delete as required and then render http://www.example.com/register/success.html. If anything fouls up, render http://www.example.com/register/error.html

Obviously, that’s a very basic example. The Success and Error pages could easily be scripts themselves, mod_mysql could be configured to forward, for example, the last_insert_id or the database error to those pages too.

All of which is configurable but not quite in the vein of ‘getting rid of stupid form and stupid form handling’ as I was thinking earlier.

No Comments

Be the first to comment!

Leave a comment