php连接数据库并登录,PHP连接服务器和MySQL实现登录

aee7c0b99fa019a633be84ac79bc76ea.png

悬赏园豆:5

[已解决问题]

解决于 2016-07-18 16:14

57e7d7b654833469823ca1a38534c098.png

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

</head>

<body>

<?php

if

(isset($_POST['button'])){

$username=$_POST['username'];//得到用户输入的用户名

$password=$_POST['password'];//密码

mysql_connect('127.0.0.1','root','')or die(mysql_error());//连接数据库

mysql_select_db('data');//选择数据库

mysql_query('set names utf8');

$sql = "select * from users//查询数据库

where username = '$username' and password='$password'";

$rs=mysql_query($sql);

if(mysql_num_rows($rs)==1){//如果数据库的行数为1则成功否则失败

echo '登陆成功';

}else{

echo '登录失败';

}

}

?>

<form id="form1" name="form1" method="post" action="">

<table width="254" border="1" align="center">

<tr>

<th colspan="2" scope="col">用户登录</th>

</tr>

<tr>

<td width="70">用户名</td>

<td width="168"><label for="username"></label>

<input type="text" name="username" id="username" /></td>

</tr>

<tr>

<td>密码</td>

<td><input type="password" name="password" id="password" /></td>

</tr>

<tr>

<td colspan="2" align="center"><label for="password">

<input type="submit" name="button" id="button" value="提交" />

</label></td>

</tr>

</table>

</form>

</body>

</html>

为什么一直会出现这样的warning:

mysql_num_rows() expects parameter 1 to be resource, boolean given in

我的代码到底是哪里出问题了,求解答

84be2cb1989a939348d3310d2cf5f103.png

kang_ya_ping

|

菜鸟二级

|

园豆:243

提问于:2016-05-12 21:29

显示帮助

使用"Ctrl+Enter"可进行快捷提交,评论支持部分 Markdown 语法:[link](http://example.com) _italic_ **bold** `code`。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值