PHP、HTML 和 CSS 的页面布局问题

发布于 2024-10-15 05:49:50 字数 3391 浏览 6 评论 0原文

由于某种原因,我的 CSS 没有将我的 div 标签格式化到页面上的正确位置。它适用于我的所有其他页面,但这个页面中的 PHP 比正常页面多得多,我想知道这是否是问题所在。 页码

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
    require("protect/serverInfo.php");
    $myusername=$_POST[Email]; 
    $mypassword=$_POST[Password];
    $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
    $count=mysql_num_rows($result);
    if($count==1){
        while($row = mysql_fetch_array($result)){
        ?>
        <div class="wrapper">
            <div class="customerHead">';
                <h1>  
                    <?php echo $row['Customer'] ?> 
                </h1>
            </div>
            <div class="customerInfoMain">
                 Company: <?php echo $row['Company'] ?><br />
                  State: <?php echo $row['State'] ?>
            </div>  
            <div class="customerCards">';
                 <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                 <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
            </div>  
            <div class="customerComments">';
                <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
            </div>
        </div>
    <?php   
        }
    }
    else {
        echo "Wrong Username or Password";
    }
?>

</body>

</html

>

CSS源

.customerCards{
    top: 150px;
    position: relative;
    width: 425px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:1;
}
.customerInfoMain{
    top: 200px;
    position: relative;
    width: 200px;
    left: 520px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}
.customerComments{
    position: relative;
    width: 200px;
    left: 580px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}

.wrapper{
    position: absolute;
    left: 50%;
    width: 900px;
    margin-left: -475px;
}

页面加载后的

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>

<link href="stylesheet.css" rel="stylesheet" type="text/css" />

</head>



<body>

Wrong Username or Password

</body>



</html>

For some reason my CSS is not formatting my div tags into the correct spots on the page. It works on all my other pages but this one has a lot more PHP in it than normal and I am wondering if that is the problem.
Page

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
    require("protect/serverInfo.php");
    $myusername=$_POST[Email]; 
    $mypassword=$_POST[Password];
    $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
    $count=mysql_num_rows($result);
    if($count==1){
        while($row = mysql_fetch_array($result)){
        ?>
        <div class="wrapper">
            <div class="customerHead">';
                <h1>  
                    <?php echo $row['Customer'] ?> 
                </h1>
            </div>
            <div class="customerInfoMain">
                 Company: <?php echo $row['Company'] ?><br />
                  State: <?php echo $row['State'] ?>
            </div>  
            <div class="customerCards">';
                 <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                 <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
            </div>  
            <div class="customerComments">';
                <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
            </div>
        </div>
    <?php   
        }
    }
    else {
        echo "Wrong Username or Password";
    }
?>

</body>

</html

>

CSS

.customerCards{
    top: 150px;
    position: relative;
    width: 425px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:1;
}
.customerInfoMain{
    top: 200px;
    position: relative;
    width: 200px;
    left: 520px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}
.customerComments{
    position: relative;
    width: 200px;
    left: 580px;
    border: 3px;
    border-style:solid;
    border-color: black;
    background-color: silver;
    z-index:2;
}

.wrapper{
    position: absolute;
    left: 50%;
    width: 900px;
    margin-left: -475px;
}

Source after page load

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />

<title>Untitled 1</title>

<link href="stylesheet.css" rel="stylesheet" type="text/css" />

</head>



<body>

Wrong Username or Password

</body>



</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如何视而不见 2024-10-22 05:49:50

这是因为如果有用户,你的包装器就会启动..
但是,如果您将包装器放在 PHP 周围,会发生什么,例如:

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="wrapper">
        <?php
        require("protect/serverInfo.php");
        $myusername=$_POST[Email]; 
        $mypassword=$_POST[Password];
        $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
        $count=mysql_num_rows($result);
        if($count==1){
            while($row = mysql_fetch_array($result)){
            ?>

                <div class="customerHead">';
                    <h1>  
                        <?php echo $row['Customer'] ?> 
                    </h1>
                </div>
                <div class="customerInfoMain">
                     Company: <?php echo $row['Company'] ?><br />
                      State: <?php echo $row['State'] ?>
                </div>  
                <div class="customerCards">';
                     <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                     <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                </div>  
                <div class="customerComments">';
                    <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
                </div>

        <?php   
            }
        }
        else {
            echo "Wrong Username or Password";
        }
        ?>
    </div>
</body>
</html>

“那么您应该有一点 CSS 操作?”

its because your wrapper just starting if there is user..
But what happend if you put your wrapper around the PHP, like:

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="wrapper">
        <?php
        require("protect/serverInfo.php");
        $myusername=$_POST[Email]; 
        $mypassword=$_POST[Password];
        $result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
        $count=mysql_num_rows($result);
        if($count==1){
            while($row = mysql_fetch_array($result)){
            ?>

                <div class="customerHead">';
                    <h1>  
                        <?php echo $row['Customer'] ?> 
                    </h1>
                </div>
                <div class="customerInfoMain">
                     Company: <?php echo $row['Company'] ?><br />
                      State: <?php echo $row['State'] ?>
                </div>  
                <div class="customerCards">';
                     <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                     <a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank"><img src="<?php echo $row['imagePathBack'] ?>" width="400px" height="303px" align="center" alt="" /></a>
                </div>  
                <div class="customerComments">';
                    <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 
                </div>

        <?php   
            }
        }
        else {
            echo "Wrong Username or Password";
        }
        ?>
    </div>
</body>
</html>

"Then you should have a little bit of the CSS action?"

Bonjour°[大白 2024-10-22 05:49:50

按目的功能和计算拆分代码并不意味着位于同一位置,html 应最后渲染。继续这样工作会给你带来很多麻烦。事情应该像这样完成:

loginProcess.php 包含:

if(isset($_SESSION["用户"]) {
$row = $_SESSION["用户"];
}
包括(“登录页面.php”);
?>

这是 longinPage.php (您可以将其中任何一个包含在您想要的位置)。要么在loginProcess.php的末尾包含loginPage.php,要么在loginPage.php的开头包含loginProcess.php

,这样loginPage.php包含

< !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">

<头>
<元内容 =“text/html; 字符集 = utf-8”http-equiv =“内容类型”/>
<标题>无标题 1
<链接 href="stylesheet.css" rel="stylesheet" type="text/css" />
< /头>

<身体>
if(isset($_SESSION['user'])) {

    < div class="wrapper">

        < div class="customerHead">';

            <h1><!---you know the row from before---/>  

                <?php echo $row['Customer'] ?> 

            </h1>

        </div>

        <div class="customerInfoMain">

             Company: <?php echo $row['Company'] ?><br />
              State: <?php echo $row['State'] ?>

        </div>  
        <div class="customerCards">';

             <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>

             < a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank">

<< img src =“”宽度=“400px”高度=“303px”对齐=“中心” alt =“”/>

        </div>  

        <div class="customerComments">';

            <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 

        </div>

    </div>

<?php   

    }

}
else {?>
     <form action="/loginProcess.php" (or loginPage.php if loginPage includes the loginProcess) method="POST">
            <input type="text" name="Email" value=""/>
            <input type="password" name="Password" value=""/>
            <input type="submit" value="login"/>
       </form>
<?php}?>

?>

首先,将显示登录表单,用户将输入他的凭据,将检查这些凭据,如果它们正常,则设置 SESSION['user'] (请记住,您需要为此启动会话),只要会话持续存在,您将不需要一直请求登录。无论如何,如果您出于某种原因不想完全分离数据库关注点/进程关注点/查看关注点,至少您必须将进程与查看分离(将数据库关注点保留在处理区域中)。在线查看一些框架或尝试找到一种更加小心地编写代码的方法,否则您将继续遇到浪费时间的无用问题。

Split the code by purpose functionality and calculations are not meant to be in the same place, html should be rendered last. Keeping on working like this will bring you a lot of trouble. Things should be done like this:

loginProcess.php contains:

if(isset($_SESSION["user"]) {
$row = $_SESSION["user"];
}
include("loginPage.php");
?>

and this is longinPage.php (you can include either of them in which on you want). Either include loginPage.php at the end of loginProcess.php or include loginProcess.php at the begining of loginPage.php

so loginPage.php contains

< !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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
< title>Untitled 1
< link href="stylesheet.css" rel="stylesheet" type="text/css" />
< /head>

< body>
if(isset($_SESSION['user'])) {

    < div class="wrapper">

        < div class="customerHead">';

            <h1><!---you know the row from before---/>  

                <?php echo $row['Customer'] ?> 

            </h1>

        </div>

        <div class="customerInfoMain">

             Company: <?php echo $row['Company'] ?><br />
              State: <?php echo $row['State'] ?>

        </div>  
        <div class="customerCards">';

             <a href ="something/<?php echo $row['imagePathFront'] ?>" target="_blank"><img src="<?php echo $row['imagePathFront'] ?>" width="400px" height="303px" align="center" alt="" /></a>

             < a href ="something/<?php echo $row['imagePathBack'] ?>" target="_blank">

< img src="" width="400px" height="303px" align="center" alt="" />

        </div>  

        <div class="customerComments">';

            <h5>Changes Made:</h5><br /> <?php echo $row['Comments'] ?> 

        </div>

    </div>

<?php   

    }

}
else {?>
     <form action="/loginProcess.php" (or loginPage.php if loginPage includes the loginProcess) method="POST">
            <input type="text" name="Email" value=""/>
            <input type="password" name="Password" value=""/>
            <input type="submit" value="login"/>
       </form>
<?php}?>

?>

first the login form will be shown and the user will input his credentials, those credentials will be checked and if they are ok the SESSION['user'] is set (remeber you need a session start for that) now as long as the session persists you will not need to request for login all the time. Anyway, if you do not want for some reason to fully separate Database Concerns/Process Concerns/Viewing Concerns, at leas you must separate the Process from the Viewing(Keeping Database concerns in the processing area). Checkout some frameworks online or try to find a way to write code with a little more care, otherwise you will keep on having useless problems that waste your time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文