0

I am trying to get the values of 3 input boxes when the submit button is clicked using PHP. However, when I run my code it shows -

Undifined Index

How should I fix this? Thanks in advance.

My Code -

<!DOCTYPE html>
<html>
<body>
<form method="post">
    <input type="number" min="0" id="Q1" name="Q1"><br>
    <input type="number" min="0" id="Q2" name="Q2"><br>
    <input type="number" min="0" id="Q3" name="Q3">
    <input type="submit" id="submit2">
</form>
<?php
    if(isset($_POST['submit2'])){
        $submitButton = $_POST['submit2'];
        if ($submitButton == true) {
          $input1 = $_POST['Q1'];
          $input2 = $_POST['Q2'];
          $input3 = $_POST['Q3'];
          echo $input1;  
        }
    }
?>
</body>
</html>
Sabad Modi
  • 45
  • 1
  • 6

1 Answers1

0

You're Almost there.

You need to add a name attribute to the submit button, I usually go with name="submit"

Then you just need to check if the submit property is set, if it is set then it means that the form was submitted and you can continue with the rest of your form checks.

if (isset($_POST['submit'])) {
  // Do something
}
Buttered_Toast
  • 901
  • 5
  • 13