Jump to content

Is this messy???


Recommended Posts

I personally find nested functions difficult to read.  I would write it.

 

$topicname_stripped = strip_tags($_POST['topicname']);
$topicname_esc = mysql_real_escape_string($topicname_stripped);

 

It's an extra line, but the combined benefit of seperate variable names and a single function per line outweighs the increase in number of lines, in my opinion.  Plus, with this method you know that you must only use a "$varname_esc" in your mysql, and never the original "$varname".  But it's all a matter of preference.

 

A good exercise is to look over old code that you wrote and see which parts you can understand easily, and which parts take some effort.  Whatever is easy to understand, use that style more often.  Whatever is confusing, stop using that style :)

Link to comment
https://forums.phpfreaks.com/topic/49895-is-this-messy/#findComment-244965
Share on other sites

If you have a form with many fields, I would use a "foreach" loop with a "switch" statement. Something like this:

<?php
if (isset($_POST['submit']))
   foreach($_POST as $fld => $val)
       switch($fld) {
              case 'fld1':
//
//    validation for fld1
//
                   break;
              case 'fld2':
              case 'fld3':
//
//  group the validations for like fields togetther
// 
                    break;
//
//  etc...
//
     }
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/49895-is-this-messy/#findComment-244995
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.