php - Prevent SQL injection with regular expression? -


possible duplicate:
best way prevent sql injection in php

i wanted ask need use else code bellow:

         if(isset($_post['submit'])) {          $username = $_post['username'];          $password = $_post['password'];          $validate = '/^[a-z]+[a-z0-9]*[.-_]*$/i';                if ((preg_match($validate , $username)==true) && (preg_match($validate ,                                                                                     $password)==true)) {                          query...                   } else {                         echo "you've used characters aren't allowed.";                }        }else {                echo 'not logged!';          } 

is regular expression save me sql injection?or can give me other suggestions make login form enought!

use mysql_real_escape_string if driver still older one, or prepared statements parameters binding if using newer pdo drivers, or mysqli_real_escape_string mysqli.

http://php.net/manual/en/function.mysql-real-escape-string.php

http://php.net/manual/en/pdo.prepared-statements.php

http://php.net/manual/en/mysqli.real-escape-string.php


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -