You could search the string for any php or JS tags, for example:
// if it finds one of the sub strings it returns true, strstr() is one of the many functions you can use
if(strstr($string, "<?") || strstr($string, "<script")) {
echo "You cannot use JavaScript or PHP!!";
} else {
// MySQL here for entering info into DB
}
hope this helps