0

This is the code in question ~ Why will num1 and num2 not get added in between the php tags. It is a youtube tutorial so no community to ask there

<form action="site.php" method="get">
    
    <input type="number" name="num1">
    <br>
    <input type="number" name="num2">
    <br>
    <input type="submit">
</form>
<br>

<?php     
    
echo $_GET["num1"] + $_GET["num2"] ?>
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – pavel Dec 06 '20 at 08:58

1 Answers1

1

In site.php...

<?php

if(isset($_GET['submit'])){

     echo $_GET["num1"] + $_GET["num2"];

}

?>


<form action="site.php" method="get">
    
    <input type="number" name="num1">
    <br>
    <input type="number" name="num2">
    <br>
    <input type="submit" name="submit" value="submit" />
</form>
<br>

PS: In a real world scenario, echo $_GET without any sanitization will expose you to security issues, but for tutorial purposes this answer should do the trick.

Oliver M Grech
  • 3,071
  • 1
  • 21
  • 36