当前位置:编程学习 > php >>

请问关于php程序的,用户登录

<?php session_start(); $conn =MySQL_connect("localhost", "root", "123456") or die("数据库链接错误"); MySQL_select_db("bbs", $conn); MySQL_query("set names gb2312"); ?> <!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> <style type="text/css"> #form1 { text-align: center; background-color: #AADFFF; } .class1 { font-weight: bold; font-size: 16px; font-family: "黑体"; } .class2 { background-color: #00BFFF; } body { background-color: #FFF; } </style></head> <?php class chkidlogin{ private $studentid; private $password; public function __construct($studentid,$password){ $this->studentid=$studentid; $this->password=$password; } public function chk(){ ; $sql=MySQL_query("select studentid from member where studentid='".$this->studentid."' and pwd='".$this->password."'"); $info=MySQL_fetch_array($sql); if($info==false){ echo "<script>alert('用户名或密码输入错误!');history.back;</script>"; exit; }else{ if($_SESSION["uid"]!=""){ session_unregister("uid"); } session_register("uid"); $_SESSION["uid"]=$this->studentid; MySQL_query("update member set logintimes+1,lastlogintime'".date("Y-m-d H:i:s").""); echo "<script>alter('登录成功!');window.location.href='bbsindex.php';</script>"; } } } $obj=new chkidlogin($_POST["studentid"],md5($_POST["password"])); $obj->chk(); ?> <body> <table width="486" height="387" border="1" cellpadding="0" cellspacing="0"> <tr> <td height="196" align="center" bgcolor="#CCFFFF"><form id="form1" name="form1" method="POST" action="bbsindex.php"> <p> <label for="studentid"></label> 学号 <input name="studentid" type="text" id="mem_id" maxlength="16" /> </p> <p> <label for="password"></label> 密码 <input name="password" type="password" id="mem_pwd" maxlength="16" /> </p> <p> <input name="reset" type="reset" class="class2" id="reset" value="重设" />  <input name="login" type="submit" class="class2" id="login" value="登录" /> </p> </form> <p>  <label for="radio"></label> </p></td> <br/> </tr> <tr> <td align="center" valign="middle" bgcolor="#CCFFFF" class="class1">广西民族大学物理实验中心论坛</td> </tr> </table> </body> </html> 运行后:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\bbs\login.php on line 44 (有小窗口显示:用户名或密码错误!) 我是用dreamweaver编写的,数据库的表z、字段是(studentid、name1、college、grade、password)
补充:那个问题其实已经解决,只是想让大家挖出里面的错误。
追问:
        	
				
是在这前面加的判断,有代码吗?obj=new chkidlogin($_POST["studentid"],md5($_POST["password"]));
$obj->chk();
答案:加QQ,我在百度信息那里留了QQ号
其他:我试了一下,也是提示用户名或密码错误,
看了下,你把运行顺序搞错了,
你一打开页面,PHP就运行了$obj=new chkidlogin($_POST["studentid"],md5($_POST["password"]));
$obj->chk();
而此时你没有填写学号和密码,所以弹出窗口。
你需要修改一下,先判断当$_POST['submit']有值的时候,再运行$obj=new chkidlogin($_POST["studentid"],md5($_POST["password"]));
$obj->chk(); 没时间看这么多的代码 这是一个坑爹的年代 火烧云学苑可以帮到你
百度一下:火烧云学苑
交流QQ:1633526387 PHP程序 

上一个:php登陆程序不管用,测试的时候显示不出页面。
下一个:java程序员跟PHP程序员哪个好点?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,