douquan2023 2014-12-04 23:09
浏览 96
已采纳

如何在php和html上隐藏div

im new on this section (html php...) I have a code, is a login form, and, i want, to hide the red box of (Incorrect user or password) from the login form but i dont know how can i do this. An screenshot: http://prntscr.com/5daqsh the code is:

<head>
  <meta charset="utf-8" />
  <title>My Website</title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
  <link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
  <link rel="stylesheet" href="css/animate.css" type="text/css" />
  <link rel="stylesheet" href="css/font-awesome.min.css" type="text/css" />
  <link rel="stylesheet" href="css/font.css" type="text/css" />
  <link rel="stylesheet" href="js/fuelux/fuelux.css" type="text/css" />
  <link rel="stylesheet" href="css/app.css" type="text/css" />
    <body background="images/login-bg.jpg">

  <!--[if lt IE 9]>
    <script src="js/ie/html5shiv.js"></script>
    <script src="js/ie/respond.min.js"></script>
    <script src="js/ie/excanvas.js"></script>
  <![endif]-->
</head>
<body>
  <section id="content" class="m-t-lg wrapper-md animated fadeInUp">    
    <div class="container aside-xxl">
      <a class="navbar-brand block" href="index.html">DameFans</a>
      <section class="panel panel-default bg-white m-t-lg">
        <header class="panel-heading text-center">
          <strong>Iniciar Sesión</strong>
        </header>
        <form action="" method="post" class="panel-body wrapper-lg">
          <div class="form-group">
                  <div class="alert alert-danger">
<?php

session_start();

include_once "conexion.php";
function verificar_login($user,$password,&$result)

    {

        $sql = "SELECT * FROM users WHERE login='$user' and pass='$password'";

        $rec = mysql_query($sql);

        $count = 0;

        while($row = mysql_fetch_object($rec))

        {

            $count++;

            $result = $row;

        }

        if($count == 1)

        {

            return 1;

        }

        else

        {

            return 0;

        }

    }
    if(!isset($_SESSION['userid']))

{

    if(isset($_POST['login']))

    {

        if(verificar_login($_POST['user'],$_POST['password'],$result) == 1)

        {

            $_SESSION['userid'] = $result->id;

            header("location:index.html");

        }

        else

        {

            echo '<div class="error">Su usuario es incorrecto, intente nuevamente.</div>';

        }

    }

?>
                  </div>
            <label class="control-label">Email</label>
            <input name="user" type="text" class="form-control input-lg">
          </div>
          <div class="form-group">
            <label class="control-label">Contraseña</label>
            <input name="password" type="password" class="form-control input-lg">
          </div>
          <div class="checkbox">
            <label>
              <input type="checkbox"> Mantener mi sesión
            </label>
          </div>
          <a href="#" class="pull-right m-t-xs"><small>Recuperar contraseña</small></a>
          <button type="submit" name="login" type="submit" value="login" class="btn btn-primary">Acceder</button>
          <div class="line line-dashed"></div>
          <a href="#" class="btn btn-facebook btn-block m-b-sm"><i class="fa fa-facebook pull-left"></i>Acceder vía Facebook</a>
          <a href="#" class="btn btn-twitter btn-block"><i class="fa fa-twitter pull-left"></i>Acceder vía Twitter</a>
          <div class="line line-dashed"></div>
          <p class="text-muted text-center"><small>¿Aún no tienes cuenta?</small></p>
          <a href="signup.html" class="btn btn-default btn-block">Crear cuenta ahora</a>
        </form>
      </section>
    </div>
  </section>


                  <div class="alert alert-success">         
                      <?php

} else {

    echo '<i class="fa fa-ban-circle"></i><strong>Ha accedido correctamente</strong> <a href="index.html" class="alert-link">Serás redirigido al panel automáticamente en breve.';

    echo '<a href="logout.php">Cerrar Sesión</a><br>';
    echo '<meta http-equiv="refresh" content="3;url=index.html">';
            


}

?>
</div>

If anyone can help me to hide the block until a user fail login in or something please :)

</div>
  • 写回答

1条回答 默认 最新

  • duanfan5012 2014-12-04 23:24
    关注

    First, you have to put your "session_start()" in the first line of your code file.

    Second, Php is the server language. So, it will be excute before any others statics language.

    In the footer, put something like this (i presume you have jQuery)

    $('.alert').hide(); //hide on load page
    

    Put your HTML normaly and in the bottom, make your login check.

    If the check is in error, do this :

    $('.alert').show();
    

    And that's it.

    If your question is "How to show HTML/JS in PHP?", do this :

    <?php echo "$('.alert').show();"?>;
    

    in a JS block and "document ready".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi