php用户登录问题
要实现的功能:用户登录一次增加一个积分,当天不累计。老是提示mysql_fetch_array()expectsparameter1toberesource.哪位告诉我问...
要实现的功能:用户登录一次增加一个积分,当天不累计。老是提示 mysql_fetch_array() expects parameter 1 to be resource.哪位告诉我问题出在哪里?
代码如下:
//用户登录
$result=mysql_query("select vid,username,userpass,usertype,zhuangtai,xingming,sheng,phone,qq,email,jifen from userlist where username='$varusername' and userpass='$varuserpass'") ;
if($rs=mysql_fetch_array($result)){
//+++增加积分+++loginlist是登录日志表
$result1=mysql_query("select vid,usertype,ip,jifen,username,logindate,beizhu from loginlist where username='$varusername' and logindate='$varlogindate'");
if($rs1=mysql_fetch_array($result1)){
//$varnewjifen=$rs['jifen'];
}else{
$varnewjifen=$rs['jifen']+1;
mysql_query("update userlist set jifen='$varnewjifen' where username='$varusername'");
} 展开
代码如下:
//用户登录
$result=mysql_query("select vid,username,userpass,usertype,zhuangtai,xingming,sheng,phone,qq,email,jifen from userlist where username='$varusername' and userpass='$varuserpass'") ;
if($rs=mysql_fetch_array($result)){
//+++增加积分+++loginlist是登录日志表
$result1=mysql_query("select vid,usertype,ip,jifen,username,logindate,beizhu from loginlist where username='$varusername' and logindate='$varlogindate'");
if($rs1=mysql_fetch_array($result1)){
//$varnewjifen=$rs['jifen'];
}else{
$varnewjifen=$rs['jifen']+1;
mysql_query("update userlist set jifen='$varnewjifen' where username='$varusername'");
} 展开
3个回答
展开全部
应该在mysql_query之后检查其结果的合理性,然后再fetch,直接fetch就会你这样的结果,应该这样写,下面这一句:
$result=mysql_query("select vid,username,userpass,usertype,zhuangtai,xingming,sheng,phone,qq,email,jifen from userlist where username='$varusername' and userpass='$varuserpass'") ;
需要修改为:
$sql="select vid,username,userpass,usertype,zhuangtai,xingming,sheng,phone,qq,email,jifen from userlist where username='$varusername' and userpass='$varuserpass'";
$result=mysql_query($sql) ;
if (! $result) exit("数据库查询失败,SQL:$sql<br>错误:".mysql_error());
$result=mysql_query("select vid,username,userpass,usertype,zhuangtai,xingming,sheng,phone,qq,email,jifen from userlist where username='$varusername' and userpass='$varuserpass'") ;
需要修改为:
$sql="select vid,username,userpass,usertype,zhuangtai,xingming,sheng,phone,qq,email,jifen from userlist where username='$varusername' and userpass='$varuserpass'";
$result=mysql_query($sql) ;
if (! $result) exit("数据库查询失败,SQL:$sql<br>错误:".mysql_error());
展开全部
话说你可以考虑一步步来更新只要做更新就可以了,不需要再查一遍数据库,直接使用sql语句的+1来实现就好了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(!$_POST)
{
?>
<div style="width:600px;">
<div style="float:left;">
<form action="" method="post">
<table border="0">
<tr><td>用户名</td><td><input type="text" width="120px" name="user" /></td></tr>
<tr><td>密码</td><td><input type="password" width="120px" name="password" /></td></tr>
<tr><td></td><td><input type="submit" width="120px" value="登录 " /></td></tr>
</table>
</form>
</div>
<div style="float:right">
<h2>没有帐号,点击注册>></h2>
</div>
</div>
<?php
}
else
{
$username = $_POST['user'];
$pw = md5($_POST['password']);
include('mysqlcon.php');
$sql = "SELECT * FROM Userdata
WHERE Username='$username' AND Password='$pw'";
if(mysql_query($sql))
{
session_start();
$_SESSION['username']=$username;
setcookie("username",$username,time()+3600);
header("location: panel.php");
exit;
}else{
header("location: index.php?action=logerror");
exit;
}
}
?>
求采纳为满意回答。
{
?>
<div style="width:600px;">
<div style="float:left;">
<form action="" method="post">
<table border="0">
<tr><td>用户名</td><td><input type="text" width="120px" name="user" /></td></tr>
<tr><td>密码</td><td><input type="password" width="120px" name="password" /></td></tr>
<tr><td></td><td><input type="submit" width="120px" value="登录 " /></td></tr>
</table>
</form>
</div>
<div style="float:right">
<h2>没有帐号,点击注册>></h2>
</div>
</div>
<?php
}
else
{
$username = $_POST['user'];
$pw = md5($_POST['password']);
include('mysqlcon.php');
$sql = "SELECT * FROM Userdata
WHERE Username='$username' AND Password='$pw'";
if(mysql_query($sql))
{
session_start();
$_SESSION['username']=$username;
setcookie("username",$username,time()+3600);
header("location: panel.php");
exit;
}else{
header("location: index.php?action=logerror");
exit;
}
}
?>
求采纳为满意回答。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询