I have a form that submits data. I would like to apply the add slashes to the $POST array. This seems to work but I get an error because add slashes has no parameters. Either i found a glitch or there is a better way of doing this.
array_walk($
POST,addslashes());

    Why do you want to add slashes to the $_POST array? You shouldn't need to do it to everything unless you're doing something "wrong".

    So what is the reason that you need every POST item passed through addslashes?

    Secondly, your code expects a function name, not a function:

    $_POST = array_walk($_POST, 'addslashes');

      Further, [man]array_map[/man] would be more appropriate in this case.

        As bpat mentioned, you're probably going about something the wrong way.

        For example, if you're trying to prepare data for a SQL query, using [man]addslashes/man should be your last resort in the event that a more suitable function doesn't exist. In your case, one most likely does; if using the mysqli or mysqli PHP extension, you should be using [man]mysql_real_escape_string/man or [man]mysqli_real_escape_string/man, respectively.

          Right you all are.
          I am trying to prep data to insert into mysql. In the past I would accomplish this by
          $var1 = addslashes($POST['var1']);
          $var2 = addslashes($
          POST['var2']);
          $var3 = addslashes($POST['var3']);
          ...
          $varN = addslashes($
          POST['varN']);

          I was just trying to write less lines of code and make the code more universal.
          - Bpat
          array_walk($_POST,'addslashes'); still has errors.

          array_map seems to be the ticket unless someone would like to enlighten me on a more correct way of doing this.

            omegared wrote:

            unless someone would like to enlighten me on a more correct way of doing this

            [man]PDO[/man]. All the escaping and whatnot done for you by the database driver.

              Write a Reply...