We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

function to filter special char

zooba123
zooba123 asked
on
Medium Priority
372 Views
Last Modified: 2012-05-11
am construct the following code
but am face some error with it
could some body help me to avoid this error
<?php

	  $connection = @mysql_connect('localhost','root','');
		if (!$connection)
	  {
	   return false;
	  } 
	  if(!mysql_select_db('shipping', $connection)) 
	  {
		  return false;
	  }

    $name = clean($_POST['name']);
	$pass = clean($_POST['pass']);
	
    $qry = "select * from users where Uname = '$name' and Upass='$pass' ";
    
    if (mysql_query($qry)) {
        echo "login successfull";
    } else {
        echo "check user or pass ";
    }
?>


<?php
// function to filter special char from input
function clean($string)
{
$specialCharacters = array(
'#' => '',
'$' => '',
'%' => '',
'&' => '',
'@' => '',
'.' => '',
'€' => '',
'+' => '',
'=' => '',
'§' => '',
')' => '',
'(' => '',
)
 
while (list($character, $replacement) = each($specialCharacters)) {
$string = str_replace($character, 'X' . $replacement . 'X', $string);
}
 
 
return $string

?>

Open in new window

Comment
Watch Question

Top Expert 2007

Commented:
Which errors do you get?
Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.