Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 6069|回复: 17
打印 上一主题 下一主题

[询问]PHP login的问题。。。劳烦大家

[复制链接]

53

主题

4

好友

795

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

跳转到指定楼层
1#
发表于 2011-6-29 12:08 AM |只看该作者 |正序浏览
index.php

  1. <html>
  2. <script>
  3. @import url(design.css);
  4. </script>
  5. <head>
  6. <title>Scholarship & Bursary - Home</title>
  7. </head>
  8. <script language="JavaScript">
  9. function Login_Validate(theForm)
  10. {
  11.         if(theForm.userid.value == "")
  12.         {
  13.                 alert('Please enter the User ID');
  14.                 theForm.id.focus();
  15.                 return(false);
  16.         }
  17.         if(theForm.password.value == "")
  18.         {
  19.             alert('Please enter the Password');
  20.                 theForm.password.focus();
  21.                 return(false);
  22.         }
  23. }
  24. </script>
  25. <body>
  26. <table align="center">
  27. <tr>
  28.         <td><img src="banner.jpg" alt="Southern College" width="1000" height="124"></td>
  29. </tr>
  30. <tr>
  31.         <td>
  32.                 <script>
  33.                 var mydate=new Date()
  34.                 var year=mydate.getYear()
  35.                 if (year < 1000)
  36.                 year+=1900
  37.                 var day=mydate.getDay()
  38.                 var month=mydate.getMonth()
  39.                 var daym=mydate.getDate()
  40.                 if (daym<10)
  41.                 daym="0"+daym
  42.                 var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
  43.                 var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
  44.                 document.write("<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"</b></font></small>")
  45.                 </script>
  46.                 <form action="login.php" name="loginForm" id="login" method="post" onsubmit="return Login_Validate(this)">
  47.                 <table align="right" style="font-size:0.8em">
  48.                 <tr>
  49.                         <td>User ID: </td>
  50.                         <td colspan="2"><input type="text" name="userid" id="userid" maxlength="11"/></td>
  51.                 </tr>
  52.                 <tr>
  53.                         <td>Password: </td>
  54.                         <td colspan="2"><input type="password" name="password" id="password" maxlength="8"/></td>
  55.                 </tr>
  56.                 <tr>
  57.                         <td></td>
  58.                         <td><input type="radio" name="lvl" id="student" value="student" checked="checked"/><label for="student">Student</label></td>
  59.                         <td><input type="radio" name="lvl" id="staff" value="staff"/><label for="staff">Staff</label></td>
  60.                 </tr>
  61.                 <tr>
  62.                         <td></td>
  63.                         <td><input type="submit" name="submit" value="Login"/></td>
  64.                         <td><input type="reset" name="submit" value="Clear"/></td>
  65.                 </tr>
  66.                 </table>
  67.                 </form>
  68.         </td>
  69. </tr>
  70. <tr>
  71.         <td style="background-color:pink">
  72.                 <a href="index.php" title="Home"><span>Home</span></a> |
  73.                 <a href="register.php" title="Register"><span>Register</span></a>
  74.         </td>
  75. <tr>
  76.         <td><hr/></td>
  77. </tr>
  78. </table>
  79. </body>
  80. </html>
复制代码
login.php

  1. <?php
  2. session_start();

  3. include("connect.php");

  4. if(isset($_POST["submit"]))
  5. {
  6.         $id = $_POST["userid"];
  7.         $password = $_POST["password"];
  8.         $lvl = $_POST["lvl"];
  9.        
  10.         if($id != "" && $password != "")
  11.         {
  12.                 if($lvl = "staff")
  13.                 {
  14.                         $result = mysql_query("SELECT * FROM staff_user WHERE userID = '$id' AND password = '$password'");
  15.                         if(mysql_num_rows($result) == 1)
  16.                         {
  17.                                 $level = mysql_result($result, '0', 'staffLVL');
  18.                                 $_SESSION['userlvl'] = $level;
  19.                                 $_SESSION['userid'] = $id;
  20.                                 echo "<script>window.location='admin.php'</script>";
  21.                         }
  22.                         else
  23.                         {
  24.                                 echo "<script>alert('Please check your USER ID and PASSWORD!')</script>";
  25.                                 echo "<script>window.location='admin.php'</script>";
  26.                         }       
  27.                 }
  28.                 else
  29.                 {
  30.                         $result = mysql_query("SELECT * FROM student_user WHERE userID = '$id' AND password = '$password'");
  31.                         if(mysql_num_rows($result) == 1)
  32.                         {
  33.                                 $_SESSION['userlvl'] = "Student";
  34.                                 $_SESSION['userid'] = $id;
  35.                                 echo "<script>window.location='applicant.php'</script>";
  36.                         }
  37.                         else
  38.                         {
  39.                                 echo "<script>alert('Please check your USER ID and PASSWORD!')</script>";
  40.                                 echo "<script>window.location='index.php'</script>";
  41.                         }
  42.                 }
  43.         }
  44.         else
  45.         {
  46.                 echo "<script>alert('Please check your USER ID and PASSWORD!')</script>";
  47.                 echo "<script>window.location='index.php'</script>";
  48.         }
  49. }
  50. ?>
复制代码
小弟新手一个...都是自学的...google找了几天都找不到解决方法
就在这一段

  1. $result = mysql_query("SELECT * FROM staff_user WHERE userID = '$id' AND password = '$password'");
  2. if(mysql_num_rows($result) == 1)
  3. {
  4.         $level = mysql_result($result, '0', 'staffLVL');
  5.         $_SESSION['userlvl'] = $level;
  6.         $_SESSION['userid'] = $id;
  7.         echo "<script>window.location='admin.php'</script>";
  8. }
  9. else
  10. {
  11.         echo "<script>alert('Please check your USER ID and PASSWORD!')</script>";
  12.         echo "<script>window.location='index.php'</script>";
  13. }
复制代码
无论我打的id和password对或错都一定会会进到else里面
出现Please check your USER ID and PASSWORD!这一段
然后会有     window.location='admin.php'"; } else { echo "    的字眼出现在网页里
我在很多情况下都会出现这种字,然后script就不会去别的page了

有人可以教教我吗?谢谢 ~.~




收藏收藏0

0

主题

0

好友

4

积分

入门会员

18#
发表于 2011-12-29 11:51 PM |只看该作者
$level = mysql_result($result, '0', 'staffLVL');
這個真的沒看過。


回复

使用道具 举报

15

主题

1

好友

168

积分

高级会员

Rank: 3Rank: 3Rank: 3

17#
发表于 2011-12-13 09:58 PM |只看该作者
string mysql_result ( resource $result , int $row [, mixed $field = 0 ] )

i found it on php.net

it doesnt wrong


回复

使用道具 举报

53

主题

4

好友

795

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

16#
发表于 2011-12-13 09:34 PM |只看该作者
这个是什么意思啊?
$level = mysql_result($result, '0', 'staffLVL');
conan0524 发表于 2011-12-13 07:05 PM



    我都忘记了咯...囧
上个学期的东西来的...


回复

使用道具 举报

15

主题

1

好友

168

积分

高级会员

Rank: 3Rank: 3Rank: 3

15#
发表于 2011-12-13 07:05 PM |只看该作者
这个是什么意思啊?
$level = mysql_result($result, '0', 'staffLVL');


回复

使用道具 举报

15

主题

1

好友

168

积分

高级会员

Rank: 3Rank: 3Rank: 3

14#
发表于 2011-12-13 07:05 PM |只看该作者
if($lvl = "staff")

if($lvl == "staff")


回复

使用道具 举报

15

主题

1

好友

168

积分

高级会员

Rank: 3Rank: 3Rank: 3

13#
发表于 2011-12-13 07:04 PM |只看该作者
if($id != "" & $password != "")

if(($id != "" )&&( $password != ""))


回复

使用道具 举报

15

主题

0

好友

118

积分

高级会员

Rank: 3Rank: 3Rank: 3

12#
发表于 2011-7-12 07:39 AM |只看该作者
这种问题解决太简单了,首先运行 sql语句看看结果是否正确,如果没问题肯定是逻辑判断出错了~


回复

使用道具 举报

53

主题

4

好友

795

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

11#
发表于 2011-7-5 10:11 AM |只看该作者
回复 10# 游戏主宰者


    有姚明高吗?


回复

使用道具 举报

3

主题

2

好友

1234

积分

黄金长老

xXpurpleXx

Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8Rank: 8

10#
发表于 2011-7-3 10:42 PM |只看该作者
回复  宅男-兜着走


   谢谢哦...login我不知不觉中就解决了... ==
只是present之前就出现问题...
反 ...
duaduawind 发表于 2011-7-3 01:42 AM

这位仁兄...你有兴趣的话明天带你去见高人


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-28 10:29 AM , Processed in 0.138459 second(s), 28 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部