if (!function_exists("GetSQLValueString")) {
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:
sayılar için GetSQLValueString($_GET['id'], "int") yada metinler için GetSQLValueString($_POST['veri'], "text")
sorgu içinde:
$sql = "INSERT INTO tablo (alan,alan2) VALUES(".GetSQLValueString($_GET['id'], "int").", ".GetSQLValueString($_POST['veri'], "text").")";
özet: verinin içindeki tırnakları \' haline getirir ve verinin sonuna-başına ' ekler. doğrudan sql'e hazırlar yani.