HTML表单不会发布数据($ _POST []为空)

时间:2019-05-25 03:04:43

标签: php html forms

我的html表单之一不是POST数据,submit按钮尊重action属性并重定向页面,因为由于某些原因,但$ _POST []为空。有人可以帮我在这里找到问题吗?

我已经尝试使用html方法POST甚至ajax处理表单并提交数据,并且没有任何情况。 $ _POST []始终保持为空(这是唯一做到这一点的页面,我拥有该表单的精确副本,但没有GET方法,并且可以正常工作...

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="nocep-rules.css" rel="stylesheet" type="text/css">
    <?php
session_start();
    $link = mysqli_connect("localhost", "xxxx", "xxxx", "xxxxxx");
        if($link === false){
        die("ERROR: Could not connect. " . mysqli_connect_error());
        }

?>
<?php 
    if(!isset($_SESSION['logged'])){
        header("location: /bubale/login.php");
    }
    ?>
</head>


<body>


    <div class="header">

    <img class="logo" src="/bubale/img/logo1.png" alt="" />
    <img class="foro-title" src="/bubale/img/loja_title.png" alt="" />
</div>  

<div class="menu">

  <nav class="site-nav">
       <ul>
          <li><a href="/bubale/logged_user.php">HOME</a></li>
          <li><a href="/bubale/lojacart.php">LOJA</a></li> 
          <li><a href="/bubale/forum2/main_foro.php">FORUM</a></li>
          <li><a href="#">CHECKOUT</a></li>
          <li><a href="/bubale/index.php?logout">SAIR</a></li>

       </ul>
  </nav>

</div>

<div class="info">
        <table width="100%">

        <tr>
          <td width="20%">
     <h2 class="text">USUÁRIO:</h2>
     <?php echo $_SESSION['logged']; ?>
     <h2 class="text2">PONTOS:</h2>
     <?php 

        $sql5= "Select points from profile where user = '".$_SESSION['logged']."'";
        $result5 = mysqli_query($link, $sql5);
        if(mysqli_num_rows($result5)==1){
        while($row5 = mysqli_fetch_assoc($result5)) {
        echo  $row5['points'];

    }
                }
                        ?>
            </td>       
          <td width="30%">
            <?php   
        $sql2= "select * from bolsinhas where user = '".$_SESSION['logged']."' && rev_id = '0'";
        $result2 = mysqli_query($link, $sql2);
        $count = mysqli_num_rows($result2);
        ?>

                <a href="/bubale/forum_bolsinhas/bolsinhas_rev.php"><h2 class="text">BOLSINHAS:</h2></a>
        <?php echo $count; ?>

                <a href="/bubale/forum_prod/produtos.php"><h2 class="text2">PRODUTOS:</h2></a>
        <?php 
        $sql3= "select * from fullsize where user = '".$_SESSION['logged']."' && rev_id = '0'";
        $result3 = mysqli_query($link, $sql3);
        $count3 = mysqli_num_rows($result3);

        echo $count3;

        ?>
            </td>
          <td>
                <?php 
                if(!empty($_SESSION["shopping_cart"])) {
$cart_count = count(array_keys($_SESSION["shopping_cart"]));

}else{$cart_count = "0";}
?>
                <a href="/bubale/cart.php"><img id="icon1" src="img/basket.png" title="Compras" ></a><span id = "count_wrapper"><a id="count">
                <?php echo $cart_count; ?></a></span>
                <a href="#"><img class="icon" src="img/sale.png" title="Promoção" alt="" ></a>
                <a href="#"><img class="icon" src="img/points.png" title="Fidelidade Buba'le" alt="" ></a>

            </td>
        </table>



    </div>

<h1 class="frete">FRETE:</h1>
    <div class="wrapper_frete">
        <?php 

                            $rua1 = $_GET['1'];
                            $numero1 = $_GET['2'];
                            $apt1 = $_GET['3'];
                            $cep1 = $_GET['4'];

                            ?>


        <table id="forma_frete" width="100%">
            <tbody>
                <th>DADOS PESSOAIS</th>
                <th>OOPS!!!</th>

            <tr>
              <form id="modform" method="POST" action="nocep2.php">
                <td width="40%" class="td2">
                    <table id="nested" width="100%">
                        <tr>
                            <td id="td-nested-left" width="30%">
            <label class="label-form" for="user">USUÁRIO:</label><br>
            <label class="label-form" for="rua">RUA:</label><br>
            <label class="label-form" for="numero">NÚMERO:</label><br>
            <label class="label-form" for="apt">APT:</label><br>
            <label class="label-form" for="cep">CEP:</label><br>

                            </td>


                            <td id="td-nested-right">
                            <input name="user" form="buttons" type="text" maxlenght="20" disabled value="<?php echo $_SESSION['logged'];  ?>" /><br>
                            <input name="rua" form="buttons" type="text" value="<?php echo $rua1; ?>" /><br>
                            <input name="numero" form="buttons" type="text" value="<?php echo $numero1;?>" /><br>
                            <input name="apt" form="buttons" type="text" value="<?php echo $apt1; ?>" /><br>
                            <input name="cep" form="buttons" type="text" value="<?php echo $cep1;?>" /> 
                            </td>
                        </tr>
                    </table>
                  <input type="submit" class="refresh" value="ATUALIZAR">
            </td>
                </form>  

                <td id="td_mensage">

                <h3 id="mensage">-irrelevant text-. </h3>   

                </td> 

                </tr>
              <tr>
                <td id="td_ob" colspan="2">
                    <h3 id="comentario">OBSERVAÇAÕ:</h3>
                    <textarea form="buttons" name="observacion" id="text_ob" placeholder="Deixe aqui sua observaçaõ..."></textarea>

                  </td>
          </tr>             
            </tbody>
      </table>


    </div>



<h1 class="frete">SUA COMPRA:</h1>  
<?php
if(isset($_SESSION["shopping_cart"])){
    $total_price = 0;
?>
<?php } ?>

<table class="table">
  <tbody>
    <tr>
      <th></th>
      <th>PRODUTO</th>
      <th>QUANTIDADE</th>
      <th>VALOR UNITARIO</th>
      <th>VALOR TOTAL</th>
    </tr>
    <?php       
foreach ($_SESSION["shopping_cart"] as $product){
?>
    <tr>
      <td id="imgtd"><img src='<?php echo $product["image"]; ?>' width="90" height="80" /></td>
      <td><?php echo $product["name"]; ?><br />
        <form method='post' action=''>
          <input type='hidden' name='code' value="<?php echo $product["code"]; ?>" />
        </form></td>
      <td><form method='post' action=''>
        <input type='hidden' name='code2' value="<?php echo $product["code"]; ?>" />
        <?php echo $product["quantity"];?>
      </form></td>
      <td><?php echo "R$".$product["price"]; ?></td>
      <td><?php echo "R$".$product["price"]*$product["quantity"]; ?></td>
    </tr>
    <?php
$total_price += ($product["price"]*$product["quantity"]);
}

?>

    <tr>
      <td class="td_tot" colspan="5" align="right"><strong id="total">TOTAL: <?php echo "R$".$total_price; ?></strong></td>
    </tr>

  </tbody>
</table>

<form method="post" action="contact-venta.php" id="buttons">
    <?php 


    ?>
    <input type="hidden" name="compras" value="<?php echo print_r($_SESSION["shopping_cart"], TRUE);  ?>"/>
    <input type="hidden" name="total" value="<?php echo $total_price; ?>">

           <input type="submit" id="submit" value="ENVIAR">
</form>


    <?php mysqli_close($link); ?>

</body>
</html>

问题在于第一次提交(一个值为ACTUALIZAR的提交),该表单将转到nocep2.php,但$ _POST []将保持为空....我张贴了整个页面,以防万一我看不到的问题。...

1 个答案:

答案 0 :(得分:3)

您的HTML相当混乱。

首先,<form><tr>中不是有效的元素。浏览器正在将它们呈现在表格之外,并与您的<input>分开。将表单标签移至<td>内,或将其移至<table>

之外

例如

<table>
<tr>
  <td>
    <form method="POST">
      <input type="text" name="inputName">
      <input type="submit">
    </form>
  </td>
</tr>
</table>

或者,如果您需要将表单分散到多个单元格中:

<form method="POST">
<table>
<tr>
  <td>
      <input type="text" name="inputName1">
  </td>
  <td>
      <input type="text" name="inputName2">
  </td>
  <td>
      <input type="submit">
  </td>
</tr>
</table>
</form>

第二,您要创建许多类型为“隐藏”的<input>元素,每个元素都有自己的表单标签,因此它们分别属于不同的表单。重新排列代码,使隐藏的元素与其余<form>出现在同一<input>