PDA

View Full Version : when inserting data... PHP+MySQL



sinus_
April 11th, 2005, 09:34 PM
hi,

what do u do when you insert data into the databse?
do you do htmlentities() or addslashes() or something else?

what do u recommend i do?

thanks :P

petefs
April 11th, 2005, 10:08 PM
function quote_smart($value) {
$value = trim($value);
// Stripslashes
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
// Quote if not integer
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}

johnlouis
April 13th, 2005, 12:52 AM
ah done. thanks. found the same code in php.net using mysql_real_escape_string()
works perfectly for me :D ty petefs :D

sinus_
April 13th, 2005, 12:54 AM
^ the post above is mine :)