我正在制作一个简单的表格,用于将数据存储到变量中。
我的HTML代码:
<form class="form-horizontal" role="form" method="post" action="result.php">
<div class="form-group">
<label for="eat" class ="control-label col-md-3">Eating:</label>
<div class="col-md-6">
<input type="number" class="form-control" id="eating" placeholder="Hours Spent Eating Everyday">
</div>
</div>
</form>
<div class="col-md-12">
<center><button type="submit" class="btn btn-default">Let's Know What You DID!</button></center>
</div>
我的PHP代码:
<?php
$eat = $_POST["eating"];
?>
我收到的错误:
注意:未定义的索引:吃东西 注意:未定义的变量:吃 请帮帮我,我正在使用WAMP和PHP 7版本。
答案 0 :(得分:1)
更改此行
<input type="number" class="form-control" id="eating" placeholder="Hours Spent Eating Everyday">
到
<input type="number" class="form-control" name="eating" placeholder="Hours Spent Eating Everyday">
POST引用了名称,而不是ID。
答案 1 :(得分:0)
在html中:
<input type="number" class="form-control" id="eating" placeholder="Hours Spent Eating Everyday" name="eating">
在php中
If(isset($_POST["eating"])){
$eating = $_POST["eating"];
}