dtkjthe4025 2016-01-12 14:25 采纳率: 0%
浏览 24

php登录没有描述[重复]

This question already has an answer here:

i have this code
here after </html> i have written my php code .
here inside my php code all code before <script> tag executes perfectly but code after <script> that it prints all php code as it is

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bookbus.ng - Merchant Login</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/datepicker3.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">

<!--[if lt IE 9]>
<script src="js/html5shiv.js"></script>
<script src="js/respond.min.js"></script>
<![endif]-->

</head>

<body>

<div class="row">
    <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
        <div class="login-panel panel panel-default">
            <div class="panel-heading">Log in</div>
            <div class="panel-body">

                <form role="form" action="login.php" method="post">
                    <fieldset>
                        <div class="form-group">
                            <input class="form-control" placeholder="E-mail"  type="email" autofocus required name="user">
                        </div>
                        <div class="form-group">
                            <input class="form-control" placeholder="Password"  type="password" value="" required name="pass">
                        </div>
                        <div class="checkbox">
                            <label>
                                <input name="remember" type="checkbox" value="Remember Me">Remember Me
                            </label>
                        </div>
                        <a href="login.php" class="btn btn-primary">Login</a>
                    </fieldset>
                </form>
            </div>
        </div>
    </div><!-- /.col-->
</div><!-- /.row -->    



<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/chart.min.js"></script>
<script src="js/chart-data.js"></script>
<script src="js/easypiechart.js"></script>
<script src="js/easypiechart-data.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script>
    !function ($) {
        $(document).on("click","ul.nav li.parent > a > span.icon", function(){        
            $(this).find('em:first').toggleClass("glyphicon-minus");      
        }); 
        $(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
    }(window.jQuery);

    $(window).on('resize', function () {
      if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
    })
    $(window).on('resize', function () {
      if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
    })
</script>   
</body>

</html>
<?php


if(isset($_POST['user']) and isset($_POST['pass']))
{
    echo "<script>alert('i am bug');</script>";//Here Is Bug
    include("include/configuration.php");   
    $username=$_POST['user'];
    $password=$_POST['pass'];
    $sql = "SELECT * FROM admin where username='$username' and password='$password'";
    $result=mysqli_query($link,$sql) or die("Error".mysqli_error($link));
    if($result)
    {
        $result2=mysqli_num_rows($result);
        if($result2)
        {

        //header("location:index.php");

        echo "yes"; //for testing
        }
        else
    {
        echo "no";
    }
    }
    else
    {
            echo "no";// for testing
    }

}
?>
</div>
  • 写回答

1条回答 默认 最新

  • duanjuhuo8772 2016-01-12 14:40
    关注

    Looks like to me you have the HTML and PHP in the same file. HTML is at the top when it should actually look something like::

    <?php
    
    echo '';
    //Close PHP tag temporarily..
    ?>
        <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bookbus.ng - Merchant Login</title>
    
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/datepicker3.css" rel="stylesheet">
    <link href="css/styles.css" rel="stylesheet">
    
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
    
    </head>
    
    <body>
    
    <div class="row">
        <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">Log in</div>
                <div class="panel-body">
    
                    <form role="form" action="login.php" method="post">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="E-mail"  type="email" autofocus required name="user">
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="Password"  type="password" value="" required name="pass">
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input name="remember" type="checkbox" value="Remember Me">Remember Me
                                </label>
                            </div>
                            <a href="login.php" class="btn btn-primary">Login</a>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div><!-- /.col-->
    </div><!-- /.row -->    
    
    
    
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/chart.min.js"></script>
    <script src="js/chart-data.js"></script>
    <script src="js/easypiechart.js"></script>
    <script src="js/easypiechart-data.js"></script>
    <script src="js/bootstrap-datepicker.js"></script>
    <script>
        !function ($) {
            $(document).on("click","ul.nav li.parent > a > span.icon", function(){        
                $(this).find('em:first').toggleClass("glyphicon-minus");      
            }); 
            $(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
        }(window.jQuery);
    
        $(window).on('resize', function () {
          if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
        })
        $(window).on('resize', function () {
          if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
        })
    </script>   
    </body>
    
    </html>
    <?php //Reopen the PHP tag for the PHP code for later.
    if(isset($_POST['user']) && isset($_POST['pass'])) //YOU USED "and" HERE, USE "&&" INSTEAD!
    {
        echo "<script>alert('i am bug');</script>";//Here Is Bug
        include("include/configuration.php");   
        $username=$_POST['user'];
        $password=$_POST['pass'];
        $sql = "SELECT * FROM admin where username='$username' and password='$password'";
        $result=mysqli_query($link,$sql) or die("Error".mysqli_error($link));
        if($result)
        {
            $result2=mysqli_num_rows($result);
            if($result2)
            {
    
            //header("location:index.php");
    
            echo "yes"; //for testing
            }
            else
        {
            echo "no";
        }
        }
        else
        {
                echo "no";// for testing
        }
    
    }
    ?>
    

    Notice that I had to reopen and close the PHP. You could use echo ''; to output HTML but single quotes in that HTML would need to escaped (Example: echo 'alert(\'Hello World!\');'; ALSO make sure the file has the *.php file extension (Example.php) so that Apache (Or whatever server you are using with PHP installed of course.) processes it properly.

    EDIT: Also make sure that PHP is installed, for Debian/Ubuntu that is "sudo apt-get update && sudo apt-get install php5"

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 关于无人驾驶的航向角
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了