Coder Profile - Show off your skills, get a coder profile.
 
 
 
code pin board MySQL Safe Query Inputs Download Source Code
Author Details Code Information
Helbom ( Ole )

Pinned 1 Codes
Posted 0 Coding Articles

Send A Message
View Coders Profile
Language PHP (Hypertext Preprocessor)
Expires Never
Length 1,287 Characters (46 Lines)
Password no password
  1. /**
  2.         * safe_query_inputs();
  3.         *
  4.         * This function helps you secure your query inputs
  5.         * before sending them to the database.
  6.         *
  7.         * Usage:
  8.         * $safeInputs = safe_query_inputs('input1','input2','input3');
  9.         *
  10.         * @return array
  11.         */
  12.        public function safe_query_inputs() {
  13.               $inputs = func_get_args();
  14.               $output = array();
  15.               foreach ( $inputs as $key => $input ) {
  16.  
  17.                      // Remove slashes if magic_quotes is enabled
  18.                      if ( get_magic_quotes_gpc() ) {
  19.                             $output[$key] = stripslashes( $input );
  20.                      }
  21.  
  22.                      // If $input is null, replace it with MySQL's keyword NULL
  23.                      if (is_null( $input )) {
  24.                             $output[$key] = 'NULL';
  25.                      }
  26.  
  27.                      // Convert booleans to 1 or 0
  28.                      elseif ( is_bool($input) ) {
  29.                             $output[$key] = ( $input ) ? 1 : 0;
  30.                      }
  31.  
  32.                      // If $input is numeric and contains decimals, replace the
  33.                      // comma with period
  34.                      elseif ( is_numeric( $input ) && ( strpos( ',' , $input ) ) ) {
  35.                             $output[$key] = str_replace( ',' , '.' , $input);
  36.                      }
  37.  
  38.                      // If $input is a normal string run it trough real_escape_string(),
  39.                      // and optionaly htmlentities();
  40.                      elseif ( !is_numeric( $input ) ) {
  41.                             #$output[$key] = htmlentities( $input );
  42.                             $output[$key] = mysql_real_escape_string( $input );
  43.                      }
  44.               }
  45.               return $output;
  46.        }
code pin board Back To Code Pin Board Post New Code
Please login to post comments.
Page 1 of 1
 
 
Latest News About Coder Profile
Coder Profile Poll
Why do you get bored with programming?

Not enough time to do something productive
I run out of ideas
Too hard to show people my creations
Everything i do has too many errors, and it's too hard
I don't get bored!!!


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
1.67 Year Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2010, Scott Thompson, All Rights Reserved