gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 15:45:44 26 4
gpt4 key购买 nike

我的一个 html 表单没有发布数据,提交按钮遵循 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[] 将保持为空....我发布了整个页面以防万一我没有看到的问题....

最佳答案

您的 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>

关于php - HTML 表单不会发布数据($_POST[] 为空),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56301365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com