4

I'm trying to create a basic input form to record new clients to a MariaDB table but my post results are coming back null.

The form for entry is set as 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 being picked up on submission. I've checked the obvious issues that come up ie no name=' attributes and correct encasing, but I'm at a complete loss

roullie
  • 2,830
  • 16
  • 26
Sakaratte
  • 128
  • 6

2 Answers2

1

I think you have a problem with your PHP script posttest.php. Your form seems to be ok.

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
hherger
  • 1,660
  • 1
  • 10
  • 13
  • I swapped my posttest.php code With the one you wrote and it was giving the same null return so it wasn't a code issue. PHPstorm was outputting to browser using localhost:63342 instead of 8080. Just need to reconfigure – Sakaratte Feb 08 '16 at 22:14
0

Nothing wrong with your HTML script. I think you are trying to refresh your posttest.php file without running your form (like without form resubmitting). if that is not the case just share your posttest.php code.
You can also use $_REQUEST which capable of dealing with $_GET and $_POST variables:

 <?php
     echo "<pre>";
     print_r($_REQUEST);
     echo "</pre>";
   ?>
  • 2
    fyi : [What's wrong with using $_REQUEST?](http://stackoverflow.com/questions/2142497/whats-wrong-with-using-request) – Ryan Vincent Feb 08 '16 at 06:27