Home >Backend Development >PHP Tutorial >关于PHP数据库的小问题
PHP 数据库 用户验证
$con=mysql_connect("localhost","root","123456");
$sql1="select count(*)from userwhere username='".$_POST['name']."' and password='".$_POST['password']."'LIMIT 1";
username='".mysql_real_escape_string($_POST['name'])."' and password='".mysql_real_escape_string($_POST['password'])."
最好做个简单的防注入措施。
http://php.net/manual/en/function.mysql-real-escape-string.php
php5.5以上版本,用mysqli_real_escape_string() 或者 PDO::quote()
$sql1 = "select count(*)from userwhere username='".$_POST['name']."' and password=='".$_POST['password']."'";
$sql1 = "select count(*)from userwhere username='$_POST[name]' and password='$_POST[password]'";
$_POST = array_map('mysql_real_escape_string', $_POST);
如果某$_POST为空,会不会报错?
直接在sql 里使用'$_POST[name]' 之类的不会出错吗..
一般都要 先判断一下吧比如 ISSET之类的.