上面 我们写了如何向数据库里面添加数据 这时候我们得做个用户登陆的程序来察看自己的资料 思路: 一 首先我们得做个页面给他登陆 二 提交给第二个页面 三 检查他是否有填写数据 3-1 获得他的数据 那就是$_POST 四 第个二个页面获得第一个页面的数据 开启SESSION以便其他的 页面用 五 检查是否符合他的密码 六 正确后列出他的资料
照样第个页面 login.html [PHP] <html> <head> <title>登陆管理</title> </head> <body> <table> <!-------提交个Login.php------> <form name="form2" method="post" action="login.php"> <tr><td>用户名:<Input type="text" name="name"></td></tr> <tr><td>密 码:<Input type="password" name="password"></td></tr> <tr><td><Input type="submit" name="submit" value="确定"> <Input type="reset" name="submit" value="取消"></td></tr> </form> </table> </body> </html> [/PHP] login.php [PHP] <? session_start(); /*开始 SESSION 一定要在第一行*/ session_register("seiname","seipass"); /*注册 seiname seipass 其实我有的页面没有注册也行 HOHO*/ $name = stripslashes($_POST['name']); /*把POST来的值赋值到 $name上*/ $password = stripslashes($_POST['password']); if($name==""||$password==""){ echo "<script>alert('不输入用户名和密码');location.href='login.html';</script>"; } /*检查他有没有填写数据*/ $db1=php; $_SESSION["seiname"]=$name; $_SESSION["seipass"]=$password; /*给SESSION 赋值*/ $conn=mysql_connect("localhost","root","root")or die("无法连接数据库"); /*连接数据库*/ $db=mysql_select_db($db1,$conn)or die("无法连接Table表"); /*打开数据库表*/ $strsql="select * from user where name='$name' and password='$password'"; /*检查他的用户名和密码*/ $result=mysql_query($strsql,$conn); /*执行操作*/ $num=mysql_fetch_object($result); /*把值赋值到$num上 至于 mysql_fetch_objedt 是PHP函数 mysql_fetch_array mysql_fetch_row 怎么用那些地方用 手册里面有说明 */ $name1=$num->name; /* $name等于等于数据库里面name*/ $password2=$num->password; /* $password2等于等于数据库里面password*/ if($num->name!=$name){ echo"<script>alert('登陆失败,请检查您的用户名和密码');location.href='login.html'</script>'"; } /*检查 数据库里面的name如果不等于他填的nama*/ elseif($num->password!=$password){ echo"<script>alert('登陆失败,请检查您的用户名和密码');location.href='login.html'</script>'"; } /*检查 数据库里面的password如果不等于他填的password*/ else echo"<meta http-equiv=refresh content=0;URL=user_info.php>"; /*输出页面 user_info.php*/ ?> [/PHP] user_info.php 思路 从login.php 获得SESSION数据 检查他是否登陆 根据SESSION的数据来获得他的其他数据 [PHP] <? session_start(); /*开启SESSION*/ if($_SESSION["seiname"]=='') { echo"<script>alert('请登陆后在来管理');location.href='login.html';</script>"; } /*检查 $_SESSION["seiname"]是否为空 如果为空就是没有登陆 记得在没有开启全局变量的情况下一定要 $_SESSION["name"]来获得数据 否则得不到数据 */ else $db1=php; /*定义表*/ $sqlname=$_SESSION["seiname"]; /*把SESSION值赋到$sqlname上 其实 你查询的时候可以直接 $_SESSION["seiname"] 但是我为了方便美观就在来个赋值的*/ $conn=mysql_connect("localhost","root","fadianji")or die("无法连接数据库"); $db=mysql_select_db($db1,$conn)or die("无法连接数据库表"); $strsql="select * from user where name='$sqlname'"; /*查询 用户名属于$sqname的资料*/ $result=mysql_query($strsql,$conn)or die("无法执行操作"); $num=mysql_fetch_object($result); /*获得所有数据*/ $name=$num->name; /*$name=数据库里面的数据*/ $password=$num->password; $img=$num->img; $fist=$num->fist; $sex=$num->sex; $dz=$num->dz; $tel=$num->tel; $oicq=$num->oicq; $time=$num->time; $mobile=$num->mobile; $work=$num->work; $img=$num->img; $info=$num->info; ?> <html> <head> <title>个人信息控制中心</title> <body topmargin="0" rightmargin="0"> <table width="750" border="0" cellspacing="0" cellspadding="0" algin="center"> <tr><td align="center">个人信息控制中心</td></tr> </table> <table cellspacing="0" cellspadding="0" border="0"> <tr> <!------Right(User_Info)---------> <td vlaign="top" width="300"> <table cellspacing="0" cellspadding="0" border="0"> <tr><td><a href="#"onClick="window.open('<?php echo $img;?>','','scrollbars=yes,resizable=yes,width=300,height=280')"><img src=<?php echo $img;?> height="90" width="90" border="0"></a></td></tr> <tr><td>名字:<?php echo $fist;?></td></tr> <!--------<?php echo $sex;?> 不用解释了吧--------------> <tr><td>性别:<?php echo $sex;?></td></tr> <tr><td>OICQ:<?php echo $oicq;?></td></tr> <tr><td>注册日期:<?php echo $time?></td></tr> <tr><td><a href="#"onClick="window.open('setpass.php','','scrollbars=yes,resizable=yes,width=300,height=180')">修改密码</a></td></tr> <tr><td><?php echo "<a href='set_info.php?'.SID.''>";?>修改个人资料</a></td></tr> </table> </td> <!--------Center(List)-----------> <td> <form method="post" action="set_info_ok.php"> <table cellspacing="0" cellspadding="0" border="0"> <tr><td>账 号:<?php echo $name;?></td></tr> <tr><td>姓 名:<Input type="text" name="ufist" value=<?php echo $fist;?>></td></tr> <tr><td>性 别:<Input type="text" name="usex" value=<?php echo $sex;?>></td></tr> <tr><td>地 址:<Input type="text" name="udz" value=<?php echo $dz;?>></td></tr> <tr><td>OICQ号码:<Input type="text" name="uoicq" value=<?php echo $oicq;?>></td></tr> <tr><td>电话号码:<Input type="text" name="utel" value=<?php echo $tel;?>></td></tr> <tr><td>手机号码:<Input type="text" name="umobile" value=<?php echo $mobile;?>></td></tr> <tr><td>工作地址:<Input type="text" name="uwork" value=<?php echo $work;?>></td></tr> <tr><td>形象照片:<Input type="text" name="uimg" value=<?php echo $img;?>> <a href="#"onClick="window.open('<?php echo $img;?>','','scrollbars=yes,resizable=yes,width=300,height=280')">点击察看</a></td></tr> <tr><td>简 介:<textarea name="uinfo" rows=8 cols=50><?php echo $info;?></textarea></td></tr> <tr><td align="center"><Input type="submit" value="确定"> <Input type="reset" value="取消"></td></tr> </table> </form> </td> <!----------Left(Link)------------> <td></td> </tr> </table> </body> </html> [/PHP] 这个页面里面我做了修改密码和修改资料的 一 同样 SESSION贯穿全局 可以检测是否登陆 二 检测他的数据是否为空 三 POST他的数据后对其数据用 update tablename set name=$name where ... 来更新他的数据 setpass.php [PHP] <? session_start(); extract($_SESSION); if($_SESSION["seiname"]=='') { echo"<script>alert('请登陆后在来管理');location.href='login.html';</script>"; } else $db1=php; $sqlname=$_SESSION["seiname"]; $conn=mysql_connect("localhost","root","root")or die("无法连接数据库"); $db=mysql_select_db($db1,$conn); $strsql="select * from user where name='$sqlname'"; $result=mysql_query($strsql,$conn); $num=mysql_fetch_object($result); $password=$num->password; ?> <html> <head><title>修改密码</title> </head> <body> <table> <form method="post" action="setpassok.php"> <tr><td>原来密码:<Input type="password" name="oldpass" value=<?php echo $password;?>></td></tr> <tr><td>新设密码:<Input type="password" name="newpass"></td></tr> <tr><td>重复密码:<Input type="password" name="rnewpass"></td></tr><br> <tr><td align="center"><Input type="submit" value="确定"> <Input type="reset" value="清空"></td></tr> </form> </table> </body> </html> [/PHP] setpassok.php [PHP] <?php session_start(); extract($_SESSION); if($_SESSION["seiname"]==''){ echo"<script>alert('请登陆在来修改密码');location.href='login.html;</script>'"; } else $sqlname=$_SESSION["seiname"]; $oldpass=$_POST['oldpass']; $newpass=$_POST['newpass']; $rnewpass=$_POST['rnewpass']; $db1=php; if($oldpass==''or$newpass==''or$rnewpass==''){ echo "<script>alert('请完整填写资料');location.href='setpass.php';</script>"; } else $sqlname=$_SESSION["seiname"]; $conn=mysql_connect("localhost","root","root")or die("无法连接数据库"); $db=mysql_select_db($db1,$conn); $strsql="select * from user where name='$sqlname' and password='$oldpass'"; $result=mysql_query($strsql,$conn)or die("无法执行查找"); $num=mysql_fetch_object($result); $password=$num->password; if($oldpass!=$password){ echo"<script>alert('旧密码不对哦!');location.href='setpass.php';</script>'"; } elseif($newpass!=$rnewpass){ echo"<script>alert('两次输入的密码不符合');location.href='setpass.php';</script>'"; } else $sqquery="update user set password='$newpass' where name='$sqlname'"; /* 其他前面的页面都解释过了 这一句就是更新数据库的SQL语句啦·牢记*/ $result1=mysql_query($sqquery,$conn)or die("错误!无法执行操作"); echo"<script>alert('修改成功');close();</script>'"; ?> [/PHP] 至于更新个人信息的数据页面我就不写 自己该写点东西了 HOHO 
|