Hi,
I would like to enquire on the appropriate steps to be taken to prevent SQL injection.
I have created a form but when I try the input '' into the field, it gives me a SQL error.
I have taken a look at the user.module in the Drupal 5 Core and realised that the it is done through the function below.
Personally, I found this solution unsatisfactory for my purpose. What if a user wishes to declare his name as O'Reily? The ' sign will prevent him from doing so while the name is perfectly legitimate.
I have done a search on the site but to no avail. Can any kind souls point me to the right direction?
Basically, I am looking for some contributed module or code snippet. Thanks in advance =)
function user_validate_name($name) {
if (!strlen($name)) return t('You must enter a username.');
if (substr($name, 0, 1) == ' ') return t('The username cannot begin with a space.');
if (substr($name, -1) == ' ') return t('The username cannot end with a space.');
if (strpos($name, ' ') !== FALSE) return t('The username cannot contain multiple spaces in a row.');
if (ereg("[^\x80-\xF7 [:alnum:]@_.-]", $name)) return t('The username contains an illegal character.');
if (preg_match('/[\x{80}-\x{A0}'. // Non-printable ISO-8859-1 + NBSP
'\x{AD}'. // Soft-hyphen