Home >Backend Development >PHP Tutorial >分未几了啊PHP数据库查询,用户信息验证

分未几了啊PHP数据库查询,用户信息验证

WBOY
WBOYOriginal
2016-06-13 11:29:21884browse

分不多了啊!PHP数据库查询,用户信息验证
首先,上代码
$username=$_POST["name"];
$password=$_POST["password"];
if($username&&$password)
{
if(strpos($username," ")!==false)echo "用户名非法";
else
{
$con=mysql_connect("localhost","root","1");
mysql_select_db("manage",$con);
$sql="
select *
from user
where username='$username' and password='$password'
";
$query = mysql_query($sql) or die(mysql_error());
$row=mysql_num_rows($query);
/*
var_dump($sql);
exit;
*/

if($row==1)echo'登录成功';
  else
  echo '登录失败';
}
}
?>
不晓得为什么,我的$row执行后获取的值是0,但是呢,我用获取到的$sql

在数据库中执行后,明明能查询到一条记录,所以能明确,SQL查询后的函数有问题,但是因为我没有什么书籍,还请大家指教。

PHP 数据库 MySQL
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn