宝塔51特惠活动,企业版1099元/年,送SSL证书,最高立减2万元!查看活动
当前位置:论坛首页 > Windows面板 > 求助

谁试下 教下我 少代码还是少表

发表在 Windows面板2020-5-15 07:24 [复制链接] 0 6808

500 - 内部服务器错误。您查找的资源存在问题,因而无法显示。

php文件夹
connect.php
?php
  $server="localhost";//主机
  $db_username="root";//你的数据库用户名
  $db_password="root";//你的数据库密码

  $con = mysql_connect($server,$db_username,$db_password);//链接数据库
  if(!$con){
    die("can't connect".mysql_error());//如果链接失败输出错误
  }

  mysql_select_db('test',$con);//选择数据库(test是数据库名称)
  //字符转换,读库
login.php
<?PHP
  header("Content-Type: text/html; charset=utf8");

  if(!isset($_POST["submit"])){
    exit("非法访问!");
  }//检测是否有submit操作

  include('connect.php');//链接数据库

  $name = $_POST['name'];//post获得用户名表单值
  $passowrd = MD5($_POST['password']);//post获得用户密码单值,使用MD5加密,不可逆

  if ($name && $passowrd){//如果用户名和密码都不为空
       $sql = "select * from admin where username = '$name' and password='$passowrd'";//检测数据库是否有对应的username和password的sql
       $result = mysql_query($sql);//执行sql
       $rows=mysql_num_rows($result);//返回一个数值
       if($rows){//0 false 1 true
                 //登录成功
                 session_start();//启动Session
                 $_SESSION['name'] = $_POST['name'];
          header("refresh:0;url=sucess.php");//如果成功跳转至sucess.php页面
          exit;
       }else{
        echo "用户名或密码错误,请重新登录!";
        echo "
          <script>
              setTimeout(function(){window.location.href='../login.html';},1000);
          </script>

        ";//如果错误使用js 1秒后跳转到登录页面重试;
       }

  }else{//如果用户名或密码有空
        echo "用户名或密码填写不完整,请重新登录!";
        echo "
           <script>
              setTimeout(function(){window.location.href='../login.html';},1000);
           </script>";
            //如果错误使用js 1秒后跳转到登录页面重试;
  }

  mysql_close();//关闭数据库
?>


<?php
  header("Content-Type: text/html; charset=utf8");

  if(!isset($_POST['submit'])){
    exit("错误执行");
  }//判断是否有submit操作

  $name=$_POST['name'];//post获取表单里的name
  $password=MD5($_POST['password']);//post获取表单里的password,使用MD5加密,不可逆

  include('connect.php');//链接数据库

  $sql = "select username from admin where username = '$name'";//SQL语句
  $result = mysql_query($sql);//执行SQL语句
  $num = mysql_num_rows($result);//统计执行结果影响的行数
  if ($num) {//如果已经存在该用户
           echo "<script>alert('温馨提示:用户存在!'); history.go(-1);</script>";
  } else {
          $q="insert into admin(id,username,password) values (null,'$name','$password')";//向数据库插入表单传来的值的sql
          $reslut=mysql_query($q,$con);//执行sql
  if (!$reslut){
    die('Error: ' . mysql_error());//如果sql执行失败输出错误
  }else{
    echo "注册成功";//成功输出注册成功
    echo "
           <script>
              setTimeout(function(){window.location.href='../login.html';},1000);
           </script>";
           //如果注册成功使用js 1秒后跳转到登录页面;
          }
  }
  mysql_close($con);//关闭数据库
?>

result.php
<?php
  header("Content-Type: text/html; charset=utf8");

  if(!isset($_POST['submit'])){
    exit("错误执行");
  }//判断是否有submit操作

  $name=$_POST['name'];//post获取表单里的name
  $password=MD5($_POST['password']);//post获取表单里的password,使用MD5加密,不可逆

  include('connect.php');//链接数据库

  $sql = "select username from admin where username = '$name'";//SQL语句
  $result = mysql_query($sql);//执行SQL语句
  $num = mysql_num_rows($result);//统计执行结果影响的行数
  if ($num) {//如果已经存在该用户
           echo "<script>alert('温馨提示:用户存在!'); history.go(-1);</script>";
  } else {
          $q="insert into admin(id,username,password) values (null,'$name','$password')";//向数据库插入表单传来的值的sql
          $reslut=mysql_query($q,$con);//执行sql
  if (!$reslut){
    die('Error: ' . mysql_error());//如果sql执行失败输出错误
  }else{
    echo "注册成功";//成功输出注册成功
    echo "
           <script>
              setTimeout(function(){window.location.href='../login.html';},1000);
           </script>";
           //如果注册成功使用js 1秒后跳转到登录页面;
          }
  }
  mysql_close($con);//关闭数据库
?>

test.php
<?php
       
?>

login.html
<!DOCTYPE html>
<html lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="css/login.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/login.js"></script>
</head>
<body>
<div class="y">
  </div>
        <div class="login">
            <div class="message"></div>
            <div id="darkbannerwrap"></div>
            <form name="login" action="php/login.php" method="post">
                        <input name="name" id="name" placeholder="请输入登录帐号" type="text" required="required" maxlength="16">
                                <hr class="hr15">
                        <input name="password" id="password" placeholder="请输入登录密码" type="password" required="required" maxlength="16">
                                <hr class="hr15">
                        <input value="登录" style="width:100%;" type="submit" name="submit">
                        <a href="result.html">注册</a>
                        <a href="#">忘记密码</a>
                                <hr class="hr20">
                </form>
        </div>

</body>
</html>

result.html
<!DOCTYPE html>
<html lang="cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<link href="css/result.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="js/result.js"></script>
</head>
<body>
        <div class="login">
            <div class="message"></div>
            <div id="darkbannerwrap"></div>
            <form name="result" action="php/result.php" method="post">
                        <input name="name" id="name" placeholder="请输入帐号" type="text" required="required" maxlength="16">
                                <hr class="hr15">
                        <input name="password" id="password" placeholder="请输入密码" type="password" required="required" maxlength="16">
                                <hr class="hr15">
                        <input name="pwd" id="pwd" placeholder="请再次输入密码" type="password" required="required" maxlength="16">
                                <hr class="hr15">
                        <input value="注册" style="width:100%;" type="submit" name="submit">
                        <a href="login.html">返回登录</a>
                        <a href="#">忘记密码</a>
                                <hr class="hr20">
                </form>
       
</body>
</html>

使用道具 举报 只看该作者 回复
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

普通问题处理

论坛响应时间:72小时

问题处理方式:排队(仅解答)

工作时间:白班:9:00 - 18:00

紧急运维服务

响应时间:3分钟

问题处理方式:宝塔专家1对1服务

工作时间:工作日:9:00 - 18:30

宝塔专业团队为您解决服务器疑难问题

点击联系技术免费分析
快速回复 返回顶部 返回列表