Jump to content

Is this messy???


Recommended Posts

from my experience you cannot use mysql_real_escape_string() until after you have connected to the database... but yes... by using strip_tags and maybe stripslashes and also mysql_real_escape_string you shohuld be pretty safe when it comes to injections

Link to comment
Share on other sites

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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.