function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
kullanım:

$ad = GetSQLValueString($_GET['ad'], "text");
$id = GetSQLValueString($_GET['id'], "int");

bütün zararlı karakterleri imha ediyoruz ve değerin başına ve sonuna ' ekliyoruz.

$kayit = "INSERT INTO ben (ad,aciklama) values($ad, $aciklama)";

değerler ' ' arasına alınmadan kullanılmalı. sprintf kullanılması daha sağlıklı bir kodlama olur.