Undefined Variable: Post - Php and Mysql

Undefined Variable: Post - Php and Mysql

I've got a form like this:

<form name="htmlform" method="post" action="script/gen.php?postData">
            <table width="450px">
                </tr>
                <tr>
                    <td valign="top">
                        <label for="customer">Customer:</label>
                    </td>
                    <td valign="top">
                        <input  type="text" name="customer" maxlength="50" size="30">
                    </td>
                </tr>

                <tr>
                    <td valign="top"">
                        <label for="nol">Number of licences: </label>
                    </td>
                    <td valign="top">
                        <input type="text" name="nol" maxlength="50" size="30">
                    </td>
                </tr>

                <tr>
                    <td>
                        <form method="post" id="submit" action="script/gen.php">
                            <input type="button" onClick="getKey()"; value="Generate key"/>
                    </td>
                </tr>



                <div id="innhold">
                            <h4>Licence Key: </h>
                </div>

                <tr>
                    <td colspan="2" style="text-align:center">
                        <input type="submit" value="Submit"> 
                    </td>
                </tr>

                </table>
            </form>

The codelines of interest is:

<input type="text" name="nol" maxlength="50" size="30">

and

<input  type="text" name="customer" maxlength="50" size="30">

I try to write this information to a database like this:

function postData($key1) {
//just to check if the key is equal to the one thats posted to the user
//echo '<h5>From postData' . $key1 . '</h5>';
/*echo '<script type="text/javascript"> alert("The order has been submitted successfully");
location = "/Webpanel/index.html";
</script>';*/

$customerVar = $POST['customer'];
$nolVar = $POST['nol'];

mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("licencedatabase");

$query_add = "INSERT INTO licence (`customer_name`,`licence_count`) VALUES ('$customerVar','$nolVar')";
$query_exec = mysql_query($query_add) or die(mysql_error()); 
mysql_close();
}

But I keep getting the error:

Undefined variable: POST

How can I accomplish this? Thanks in advance.

3

6 Answers

Its $_POST not $POST.

$customerVar = $_POST['customer'];
$nolVar = $_POST['nol'];

That's because it's called $_POST.

Try using $_POST instead of $POST

to access the superglobal POST use $_POST not $POST

All PHP superglobals (such as those for GET and POST) are prefixed with an underscore, so: $POST should be $_POST.

Have a look here for more information about the available superglobals in PHP:

Try using $_POST instead of $POST

Check following example:

The predefined $_POST variable is used to collect values from a form sent with method="post".

Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

Example:

<form action="submitform.php" method="post">
    Name: <input type="text" name="fname" />
    Age:  <input type="text" name="age" />
    <input type="submit" />
</form>

When the user clicks the "Submit" button, the URL will look like this:

The "submitform.php" file can now use the $_POST variable to collect form data (the names of the form fields will automatically be the keys in the $_POST array):

Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?>  years old. 

might you will understand clearly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.