0

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.

2 Answers2

1

Change this line

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

to

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

POST is referencing the name, not the ID.

Ben
  • 345
  • 2
  • 10
0

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"];
}
bradley546994
  • 630
  • 2
  • 12
  • 30
  • Alright, fixed all my errors. Thanks alot! –  Nov 26 '16 at 15:03
  • I am getting error at this line: $totalhours = $eating; and the error is: Undefined variable: eating –  Nov 26 '16 at 15:05
  • @AviThour This is likely because you aren't entering a value for eating when the form is being submitted. This means the variable isn't set because of the is set check. – Ben Nov 26 '16 at 15:08
  • @Ben I am entering a value for sure and i don't know why its error. –  Nov 26 '16 at 15:10