因此,我正在尝试将一些数据从HTML表单发布到PHP脚本。这是我正在使用的表格:
<form style="border: 1px solid black; border-radius: 5px; padding: 10px;" action="order2.php" method="post">
<div class="form-group">
<label>Service Type</label>
<select class="form-control" id="service">
<?php
$sql = "SELECT name FROM services ORDER BY name ASC";
$statement = $mysqli->prepare($sql);
$statement->execute();
$statement->store_result();
$result = get_result($statement);
while($data = array_shift($result)) {
echo('<option>'.$data['name'].'</option>');
}
?>
</select>
<small id="serviceHelp" class="form-text text-muted"></small>
</div>
<div class="form-group">
<label>Amount</label>
<input type="number" class="form-control" id="amount" placeholder="1000">
<small id="priceHelp" class="form-text text-muted"></small>
</div>
<div class="form-group">
<label>Link</label>
<input type="text" class="form-control" id="link" placeholder="">
<small id="linkHelp" class="form-text text-muted"><strong>Warning</strong>! Please keep to the format of the example provided!</small>
</div>
<div class="form-group">
<label>e*pvp Username</label>
<input type="text" class="form-control" id="username" placeholder="i0N">
<small id="linkHelp" class="form-text text-muted"><strong>Warning</strong>! Please make sure your username is correct (copy & paste it), because the payment will fail otherwise!</small>
</div>
<div style="text-align: center;"><button type="submit" class="btn btn-danger" style="padding-left: 30px; padding-right: 30px;">Submit</button></div>
</form>
正如您在顶部看到的那样,“方法”设置为“发布”。表单成功地重定向了我,当我通过检查器查看请求时,它还显示出发出了POST请求。但是,没有任何数据通过。如果我尝试var_dump($_POST);
,它也只显示array(0) { }
。我想念什么?
提交表单时,我还在error_log中永久收到此PHP错误:
[30-Jul-2018 04:14:28 America/New_York] PHP Notice: Undefined index: service in /home/maxkygbx/public_html/epvpsocial/order2.php on line 6
[30-Jul-2018 04:14:28 America/New_York] PHP Notice: Undefined index: service in /home/maxkygbx/public_html/epvpsocial/order2.php on line 7
以下是对应的行:
<?php
if(is_null($_POST['service']) || $_POST['service'] == ""){
echo($_POST['service']);
die();
}
答案 0 :(得分:3)
要发送POST
或GET
,您的输入应具有name
属性
之后,您可以访问它
HTML
<input type='text' name='phone'>
PHP
<?php echo $_POST['phone'];
答案 1 :(得分:3)
您的输入字段没有任何“名称”属性。
您的输入必须像这样:
dependencies {
...
compile project(':my-generator')
...
}
答案 2 :(得分:-1)
查询字符串(名称/值对)在GET或POST请求的URL中发送:
/stacktest/example_form.php?name1=value1&name2=value2
该名称是使用POST
或GET
方法时需要的锚标记。因此,您需要使用name
值,以便链接和保存这些值。