Home > Backend Development > PHP Tutorial > PHP新手求助

PHP新手求助

WBOY
Release: 2016-06-23 13:59:22
Original
1195 people have browsed it

我是新手,刚刚做了一个测试程序。数据库是mydb,里面只有一张表user;程序的功能是从mydb里查询用户名和客码。
可是每次运行都不能返回结果,不知道为什么。
代码如下:



  if(!get_magic_quotes_gpc())
  echo "magic_quotes_gpc is off";

$uname=$_POST['uname'];
$input_passwd=$_POST['passwd'];

echo $uname.'';
echo $input_passwd.'';

$db=new mysqli('localhost','root','','mydb');

if(mysqli_connect_errno())
{
echo 'mysqli connect error' ;
exit;
}

$query="select * from mydb.user where name=$uname";

echo $query.'';

$result=$db->query($query);

$num_result=$result->num_rows;

for($i=0;$i!=$num_result;$i++)
{
$row=$result->fetch_assoc();
echo $row['name'].'----------'.$row['passwd'].'';
}

$result->free();
$db->close();

?>

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template