-1

Code:

if($amount==300)    
{       
 echo"Value: <textarea name='input1' id='input1' width='50px' height='500px'></textarea>"."<br/><br/>";     
$input1=$_POST['input1'];

When we use $input1 it is showing a message following :

Undefined index: input1 in C:\xampp\htdocs\astrologyProject\inputAmount.php on line 15

What is the problem ?

Rikesh
  • 26,156
  • 14
  • 79
  • 87

2 Answers2

0

Use isset(..) to check if the variable is set.

$input1 = isset($_POST['input1']) ? $_POST['input1'] : 0;
putvande
  • 15,068
  • 3
  • 34
  • 50
0

What you should do:

  1. You receive an HTTP request
  2. You send a form to the browser
  3. The browser sends the from data in another HTTP request
  4. You read the data from the form

What you are actually doing is trying to read the form data during steps 1/2. The data doesn't exist then.

You need to either:

  • Move the code that reads the data to another PHP program which the action of the form points to or
  • Test to see if the form data exists (if/isset) before trying to process it while setting the action to the same program.
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335