Null values ​​on $ _post

I am trying to create a basic input form for writing new clients to the MariaDB table, but my publication results return to zero.

The entry form is set below

<form class="clientreg" id="NewClient" method="post" action="posttest.php">
    <label>Client Name:
        <input type="text" name="ClientName" class="LongText"/>
    </label>
    <label>Bulk Discount: <input type="number" name="Bulk" class="discount"/></label>
    <label>Settlement Discount: <input type="number" name="settlement" class="discount"/></label>
    <label>Trades Discount: <input type="number" name="Trades" class="discount"/></label>
    <input type="submit"/>
</form>

print_r($_POST)returns Array(), so the information is not selected when sending. I checked the obvious problems that arise, i.e. No name=' attributesand fix coding, but I completely lost

+4
source share
2 answers

I think you have a problem with your PHP posttest.php script. Your form looks fine.

HTML

<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<title>just for test</title>
</head>
<div id="Response" ></div>
<h3>login</h3>
<form class="clientreg" id="NewClient" method="post" action="posttest.php">
    <label>Client Name:
        <input type="text" name="ClientName" class="LongText"/>
    </label>
    <label>Bulk Discount: <input type="number" name="Bulk" class="discount"/></label>
    <label>Settlement Discount: <input type="number" name="settlement" class="discount"/></label>
    <label>Trades Discount: <input type="number" name="Trades" class="discount"/></label>
    <input type="submit"/>
</form>
</div>
</body>
</html>

posttest.php

<?php
echo '<pre>'; print_r($_POST); echo '</pre>';
foreach($_POST as $key=>$val) {
    echo "\$_POST[$key]=$val<br />";
}
?>

Result

Array
(
    [ClientName] => MyName
    [Bulk] => 1
    [settlement] => 2
    [Trades] => 3
)
$_POST[ClientName]=MyName
$_POST[Bulk]=1
$_POST[settlement]=2
$_POST[Trades]=3
+1
source

HTML script. , posttest.php (, ). , posttest.php.
$_REQUEST, $_GET $_POST:

 <?php
     echo "<pre>";
     print_r($_REQUEST);
     echo "</pre>";
   ?>
0

Source: https://habr.com/ru/post/1627718/


All Articles