Removing ' and / from submits

zMagenta

Posting Freak
Jul 15, 2011
1,414
682
Hi!

Is there anyway to remove the characters - ' and / from getting submitted into a DB as most of the time it causes MySQL errors?

Thanks!
 

Tranquilizer

Active Member
Jan 24, 2012
164
16
I use this function for replacing characters (it currently removes apostrophes):
Code:
function clean_up( $text ) {
    $unwanted = array("'"); // add any unwanted char to this array
    return str_ireplace( $unwanted, '', $text );
}
Put whatever character you want to be replaced with nothing in the $unwanted. Then when you're selecting or inserting use clean_up($variable). In your case use:
Code:
<?php
if(isset($_POST['submit'])){
$variable = clean_up($_POST['fieldhere']);
}
?>
If you're inserting or updating a variable into the database you might want to mysql_real_escape_string that variable.
Hope this helps :)
 

Users who are viewing this thread

Top