log.php<?php
include 'function.php';
$had = $_GET['act'] ;
if ( $had == "fal" || $had ==""){
login();
}
/*if( $had =="ace"){
echo $had;
}*/
$text = "";
?><!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>
<script>
function check(){
if(document.log.Uname.value == "" ||document.log.Upwd.value == ""){
alert("用户名或密码不能为空!");
return false;
}
}
function check2(){
if(document.message.area.value==""){
alert("您的评论不能为空!");
return false;
}
}</script>
</head><body>
<form action="act.php" method="post" name="message" onsubmit="return check2()">
<table align="center"> 
  <tr>
    <td width="661" colspan="6" align="center"><textarea name="area" style="border:1px dashed #966; height:60px; width:640px; text-align:left; overflow-y:auto"><?= $text ?></textarea></td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"><input type="submit" value="提交" /></td>
  </tr>
  </table>
</form></body>
</html>act.php<?php
include 'db.php';
$User       =$_POST['uname'];
$Upwd       =$_POST['upwd'];
echo '$User='.$User.'<br />';
echo '$Upwd='.$Upwd.'<br />';
select_usinfo();
if ($User == $row_select_usinfo['usname'] and $Upwd == $row_select_usinfo['uspwd']){
header("location:log.php?act=ace");
} else {
header("Location:log.php?act=fal");
}
?>function.php<?php
function login(){
 echo"<form action='act.php' method='post' name='log' onsubmit='return check()'>
<table width='640' style='border:1px solid #ccc' align='center'>
  <tr>
    <td width='9%'>用户名</td>
    <td width='28%'><input name='uname' type='text'  size='23'/></td>
    <td width='9%'>密&nbsp;&nbsp;码</td>
    <td width='29%'><input type='password' name='upwd'  size='23'  /></td>
    <td width='8%'><input type='submit' value='登录'  /></td>
    <td width='17%'>注册</td>
  </tr>
</table>
</form> ";
}?>db.php<?
$host           = "localhost" ;
$user           = "root" ;
$password       = "root" ;
$database       = "chat" ; 
function dbconnect($host,$user,$password,$database){

mysql_connect($host,$user,$password)
or die ("登录数据库失败") ;
mysql_select_db($database)
or die ("连接数据库失败!");
}dbconnect($host,$user,$password,$database);//查询用户信息
function select_usinfo(){
$select_usinfo                  = "select * from usinfo ";
$result_select_usinfo           = mysql_query($select_usinfo)
or die("查询失败!" . mysql_error()) ;
$row_select_usinfo              = mysql_fetch_array($result_select_usinfo) ;
?>本人菜鸟,刚刚开始学php,希望有前辈帮忙解决下!在线等

解决方案 »

  1.   

    if(document.log.Uname.value == "" ||document.log.Upwd.value == ""){   改成
    if(document.log.uname.value == "" ||document.log.upwd.value == ""){
      

  2.   

    你把你登陆界面的网址复制一下, 再重新打开一个浏览器窗口,将刚才的那个复制的网址粘贴过来,也可以登陆的。原因是你登陆的时候没有session。 你试试看看
      

  3.   


    你能帮我示例下,这个sission应该怎么加,代码我贴出去了
      

  4.   

    这个在百度搜下肯定有,我以前做ASP.NET的时候,就是这种情况,后来加个session就好了。比如你打开你的邮箱,把这个网址复制一下,重新打开浏览器,复制网址就进不去邮箱了。 具体怎么写你搜搜,我对PHP不是太了解,我想这些东西都是大同小异的。  我去吃午饭了
      

  5.   

    问题是:我echo出来的$row_select_usinfo['uname']和$row_select_usinfo['upwd']跟我登录其实是相等的,可是为什么,这程序就是给我显示登录失败呢?跪求解释! 
      

  6.   

    act.php
    这一行的 and php好像不是这样吧, && 
    if ($User == $row_select_usinfo['usname'] and $Upwd == $row_select_usinfo['uspwd']){