function ป้องกัน SQL injection สำหรับ php


หน้าแรก PHP MySQL เกร็ดความรู้ function ป้องกัน SQL injection สำหรับ php
ลองเอาไปทดสอบดูนะครับ



  Code
function CheckInject($strTxt)
{
$strTxt = str_replace("'", "''", $strTxt);
$strTxt = str_replace("--", "", $strTxt);
return $strTxt;
}

$strTxtSQL = " SELECT * FROM tbl_name WHERE id= '".CheckInject($_GET["id"])."' ";



ขึ้นไปด้านบน