Wednesday 6 June 2018

php - HTML form WON'T POST data ($_POST[] is empty)



One of my html forms is not POSTing data, the submit button respect the action attribute and redirect the page as spected BUT $_POST[] is empty for some reason. could sonebody help me find the issue here?



I already tried using html method POST and even ajax to process the form and submit the data, and theres no case. $_POST[] will allways stay empty (this is the only page that does that, I hava an exact copy of the form but without the GET method and it works fine...








Untitled Document


session_start();

$link = mysqli_connect("localhost", "xxxx", "xxxx", "xxxxxx");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

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

?>
























USUÁRIO:



PONTOS:



$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'];

}
}
?>


$sql2= "select * from bolsinhas where user = '".$_SESSION['logged']."' && rev_id = '0'";
$result2 = mysqli_query($link, $sql2);
$count = mysqli_num_rows($result2);
?>

BOLSINHAS:




PRODUTOS:



$sql3= "select * from fullsize where user = '".$_SESSION['logged']."' && rev_id = '0'";
$result3 = mysqli_query($link, $sql3);
$count3 = mysqli_num_rows($result3);

echo $count3;

?>


if(!empty($_SESSION["shopping_cart"])) {
$cart_count = count(array_keys($_SESSION["shopping_cart"]));

}else{$cart_count = "0";}
?>












FRETE:





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

?>






















DADOS PESSOAIS OOPS!!!



























-irrelevant text-.




OBSERVAÇAÕ:












SUA COMPRA:


if(isset($_SESSION["shopping_cart"])){
$total_price = 0;
?>













foreach ($_SESSION["shopping_cart"] as $product){
?>







$total_price += ($product["price"]*$product["quantity"]);
}


?>






PRODUTO QUANTIDADE VALOR UNITARIO VALOR TOTAL


" />


" />

TOTAL:






?>
"/>













the issue is with the first submit (the one with the value ACTUALIZAR), the form will go to nocep2.php BUT $_POST[] will remain empty .... I posted the entire page just in case there is an issue I'm not seeing....


Answer



Your HTML is rather confused.




Firstly,

is not a valid element in . The browser is rendering them outside the table, and separate from your . Move your form tags inside the , or move them outside the



Eg
















Or, if you need to spread your form over several cells:






















Secondly, you're creating a number of elements of type "hidden", each with their own form tags, so they are each part of a different form. Reorder your code so that the hidden elements appear within the same

as the rest of your


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...