From: Paul Fine [mailto:[EMAIL PROTECTED]

> Greetings!
> 
> Is it common practice to name script variables/form data in 
> say PHP to match the appropriate colums in the db tables?
> 
> I can see how this makes sense, however in the little work I 
> have done I preferred to do the opposite as it seems to be 
> helpful to keep a distinction.


I've found it useful to keep the same names, such that you could do the following. Say 
you were taking form input and inserting it as a row into the table...

<?

$query = "INSERT INTO table SET ";

foreach ($_POST as $key => $val) {
        $query .= "$key='$val', ";
}

$query = preg_replace("/, $/", "", $query);

mysql_query($query);

?>

That's oversimplifying it, for sure, as you'd want error checking and data validation 
and the like. And you also have to remember that any fields in the HTML form, hidden 
or otherwise, had better match up to the db table structure.

On the plus side, if you add a column to the db, all you need to do is add a field of 
the same name to the HTML form.

In a nutshell, while it's useful to do things like abstract the construction of the 
query, it's often not worth the trouble.


-- 
Mike Johnson
Web Developer/Systems Asst.
Smarter Living, Inc.
phone (617) 497-2500 x226

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to