未定义变量:POST - PHP和MySQL

3

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>

感兴趣的代码行是:
<input type="text" name="nol" maxlength="50" size="30">

并且

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

我尝试像这样将这些信息写入数据库:
```html

我尝试像这样将这些信息写入数据库:

```
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();
}

但是我一直收到这个错误信息:
Undefined variable: POST

我该如何完成这个任务呢?先在此感谢您的提前帮助。

我正在使用Notepad++和WAMP本地测试,并在Chrome上使用Firebug插件。 - Tobias Moe Thorstensen
一个非常快速和简单的谷歌搜索就能立即给你答案... - Jocelyn
所有的mysql_*函数都已经被弃用,如PHP手册的每一页所示:不建议使用此扩展。相反,应该使用MySQLiPDO_MySQL扩展。 - Jocelyn
6个回答

11

应该使用$_POST而不是$POST

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

3
那是因为它被称为$_POST

3

尝试使用$_POST代替$POST


2

访问超全局变量POST时,请使用$_POST而不是$POST


1

尝试使用$_POST而不是$POST

请查看以下示例:

预定义的$_POST变量用于从使用method="post"发送的表单中收集值。

使用POST方法发送的表单信息对其他人不可见,并且没有发送信息的限制。

示例:

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

当用户点击“提交”按钮时,URL 将会变成这样:http://localhost/submitform.php
现在,“submitform.php”文件可以使用“$_POST”变量来收集表单数据(表单字段的名称将自动成为“$_POST”数组中的键)。
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?>  years old. 

也许你会清楚地理解。


1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接