Avi Thour Avi Thour - 13 days ago 8
HTML Question

PHP Ver 7 - Undefined index: eating - Post method

I was making a simple form for getting data stored into variable.

My HTML Code:

<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>





MY PHP Code:

<?php
$eat = $_POST["eating"];
?>


Error I'm Getting:


Notice: Undefined index: eating
Notice: Undefined variable: eating
Please help me out, I am using WAMP with Version 7 of PHP.

Answer

In html:

<input type="number" class="form-control" id="eating" placeholder="Hours Spent Eating Everyday" name="eating"> 

In php

If(isset($_POST["eating"])){
 $eating = $_POST["eating"];
}