PHP:PHP 输出呈现在意想不到的地方

问题描述 投票:0回答:1

body {
  margin: 0;
  background-color: beige;
}

fieldset,
header,
footer {
  font-family: Raleway;
  font-weight: bold;
}

header {
  height: 150px;
  background-color: #1F006A;
}

footer {
  background-image: linear-gradient(to left top, #d16ba5, #c777b9, #ba83ca, #aa8fd8, #9a9ae1, #8aa7ec, #79b3f4, #69bff8, #52cffe, #41dfff, #46eefa, #5ffbf1);
  height: 125px;
}

.headertext {
  font-size: 28pt;
  margin: 20px 24px;
  color: #03CCA9;
}

a {
  color: #FF00B3;
  transition-duration: 0.2s;
}

a:visited {
  color: #4C00FF;
  transition-duration: 0.7s;
}

a:hover {
  color: #04FFD4;
  transition-duration: 0.2s;
}

form {
  text-align: center;
  margin: 0;
}

fieldset:not(:last-of-type) {
  margin-right: 16px;
}

fieldset {
  border-style: double;
  border-width: 8px;
}

input[type="date"] {
  width: 100%;
}

.klienci {
  border-color: blueviolet;
}

.praca {
  border-color: #03CCA9;
}

.pracownicy {
  border-color: #7C9FF7;
}

.produkty {
  border-color: #B1FF00;
}

.zamówienia {
  border-color: #FF9780;
}

.pos-rel {
  position: relative;
}

@keyframes anim-fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.anim-abs {
  position: absolute;
  width: 24px;
  height: 24px;
  animation: anim-fadein 0.3s ease-in forwards;
}

.animelem-1 {
  top: 0;
  left: 0px;
}

.animelem-2 {
  bottom: 0;
  right: 0px;
  transform: rotate(180deg);
}

.flex-center {
  display: flex;
  justify-content: center;
}

.fx-ai-c {
  align-items: center;
}

.flex-row {
  flex-direction: row;
}

.min-padding {
  padding: 1vw;
  box-sizing: border-box;
  height: calc(100vh - 275px);
  min-height: 265px;
}
<html>

<head>
  <meta charset="UTF-8">
  <title>Interfejs sieciowy - Jakub Namyślak</title>
  <link rel="stylesheet" type="text/css" href="style.css">
  <meta name="author" content="Jakub Namyślak">
  <meta name="description" content="Interfejs sieciowy baz danych Jakuba Namyślaka.">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Raleway&display=swap" rel="stylesheet">
</head>

<body>
  <header class="flex-center flex-center fx-ai-c">
    <div class="pos-rel">
      <img class="anim-abs animelem-1" src="corner-anim1.png" alt="An animation asset">
      <h1 class="headertext">✧ Interfejs sieciowy - Jakub Namyślak</h1>
      <img class="anim-abs animelem-2" src="corner-anim1.png" alt="An animation asset">
    </div>
  </header>
  <main class="flex-center flex-row min-padding fx-ai-c">
    <fieldset class="klienci flex-center fx-ai-c">
      <legend>Klienci</legend>
      <form action="#" method="POST">
        <input type="hidden" name="form_id" value="klienci" required>

        <input type="number" name="obsługa_klienta" value="1" placeholder="obsługa klienta" required></input>
        <input type="number" name="id_zamówienia" value="8" placeholder="id zamówienia"></input>
        <br>
        <br>
        <input type="text" name="imie" value="Tadeusz" placeholder="imię" required></input>
        <input type="text" name="nazwisko" value="Rydzyk" placeholder="nazwisko" required></input>
        <br>
        <input type="text" name="mail" value="[email protected]" placeholder="e-mail" required></input>
        <input type="text" name="telefon" value="+48637436763" placeholder="numer telefonu" required></input>
        <br>
        <br>
        <input type="text" name="miasto" value="Chabry" placeholder="miasto" required></input>
        <input type="text" name="ulica" value="Słowackiego" placeholder="ulica" required></input>
        <br>
        <input type="text" name="kod_pocztowy" value="19-438" placeholder="kod pocztowy" required></input>
        <input type="text" name="numer_domu" value="21/38" placeholder="numer domu" required></input>
        <br>
        <br>
        <button type="submit">Prześlij (klient)</button>
      </form>
    </fieldset>

    <fieldset class="pracownicy flex-center fx-ai-c">
      <legend>Pracownicy</legend>
      <form action="#" method="POST">
        <input type="hidden" name="form_id" value="pracownicy" required>

        <input type="number" name="praca" value="1" placeholder="nr pracy" required></input>
        <br>
        <br>
        <input type="text" name="imie" value="Michał" placeholder="imię" required></input>
        <input type="text" name="nazwisko" value="Kaczyński" placeholder="nazwisko" required></input>
        <br>
        <input type="text" name="mail" value="[email protected]" placeholder="e-mail" required></input>
        <input type="text" name="numer" value="+48637436763" placeholder="numer telefonu" required></input>
        <br>
        <br>
        <button type="submit">Prześlij (pracownicy)</button>
      </form>
    </fieldset>

    <fieldset class="produkty flex-center fx-ai-c">
      <legend>Produkty</legend>
      <form action="#" method="POST">
        <input type="hidden" name="form_id" value="produkty" required>
        <input type="text" name="nazwa_produktu" value="Szpadel" placeholder="nazwa produktu" required></input>
        <br>
        <input type="number" name="cena_produktu" value="4.99" placeholder="cena produktu" required></input>
        <br>
        <br>
        <button type="submit">Prześlij (pracownicy)</button>
      </form>
    </fieldset>

    <fieldset class="zamówienia flex-center fx-ai-c">
      <legend>Zamówienia</legend>
      <form action="#" method="POST">
        <input type="hidden" name="form_id" value="zamówienia" required>
        <input type="date" name="data_zamówienia" required></input>
        <br>
        <input type="number" name="produkt" value="7" placeholder="produkt (id)" required></input>
        <br>
        <br>
        <button type="submit">Prześlij (pracownicy)</button>
      </form>
    </fieldset>

    <fieldset class="praca flex-center fx-ai-c">
      <legend>Praca</legend>
      <form action="#" method="POST">
        <input type="hidden" name="form_id" value="praca" required>

        <input type="text" name="praca" value="Sprzątaczka" placeholder="praca" required></input>
        <br>
        <br>
        <button type="submit">Prześlij (praca)</button>
      </form>
    </fieldset>
  </main>
  <!--<?php
            $servername = "localhost";
            $username = "administrator";
            $password = "root";
            $dbname = "jn_sklep";

            $conn = mysqli_connect($servername, $username, $password, $dbname);

            function displayData(){
                $tytuły = array(
                            "klienci" => array("Obsługa klienta", "Id zamówienia", "Imię", "Nazwisko", "E-mail","Numer telefonu", "Miasto", "Ulica", "Kod pocztowy", "Numer domu"),
                            "pracownicy" => array("Numer pracy", "Imię", "Nazwisko", "E-mail", "Numer telefonu"),
                            "produkty" => array("Nazwa produktu", "Cena produktu"),
                            "zamówienia" => array("Data zamówienia", "Id produktu"),
                            "praca" => array("Nazwa stanowiska")
                        );
                
                echo "<table><tr>";

                foreach($tytuły[$_POST["form_id"]] as $kom){
                    echo "<th>", $kom, "</th>";
                }

                echo "</tr>";
            }

            displayData();
        ?>-->
  <footer class="flex-center fx-ai-c">
    <h2>© <a href="https://shatterwares.com" target="_blank">Jakub Namyślak</a>. All rights reserved.</h2>
  </footer>
</body>

</html>

所以我今天一直在做一个项目,遇到了一个问题:包含的php代码最终出现在一个意想不到的地方。前面提到的应该返回它的值上面页脚,但是对于未知原因,它位于下方(嵌入 1、1.2 和 1.3)仅当

foreach($tytuły[$_POST["form_id"]] as $kom)
循环与
$_POST
数组以任何方式交互时才会发生;将字母放入回声中可使其恢复正常(嵌入 2)。

我设法发现的是:

  • <table>
    标签似乎呈现在页脚下方
    ,并且那里据说没有与html或css相关的问题;
  • 无论提交的是哪一个,都只能通过尝试回显表单值来复制错误;
  • 与 PHP 未接收表单数据相关的警告出现在预期位置;它们仅在提交任何表单之前出现,并且 与问题无关。
编辑:该网站不支持 PHP,尽管我在评论中留下了预览中的代码。

嵌入1:

嵌入1.2和1.3(html结构):

php html mysql foreach echo
1个回答
0
投票
感谢@Iłya Bursov,问题已经找到 - 我忘记关闭桌子了。

© www.soinside.com 2019 - 2024. All rights reserved.