I am trying to do a simple value check from a form and I want to assign some variables the values entered by the user. I have done this form :
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<label for="raspuns1"><span class="glyphicon glyphicon-pencil"></span> Raspuns subpunct a</label>
<input type="text" class="form-control" name="raspuns1" placeholder="Raspuns a"><br>
<label for="raspuns2"><span class="glyphicon glyphicon-pencil"></span> Raspuns subpunct b</label>
<input type="text" class="form-control" name="raspuns2" placeholder="Raspuns b"><br>
<label for="raspuns3"><span class="glyphicon glyphicon-pencil"></span> Raspuns subpunct c</label>
<input type="text" class="form-control" name="raspuns3" placeholder="Raspuns c"><br>
<label for="raspuns4"><span class="glyphicon glyphicon-pencil"></span> Raspuns subpunct d</label>
<input type="text" class="form-control" name="raspuns4" placeholder="Raspuns d"><br>
<button type="submit" class="btn btn-success glyphicon glyphicon-check"> Verifica răspunsurile</button>
</form>
and this is the php code
<?php
$corect1="raspunsulcorect";
$corect2="raspunsulcorect";
$corect3="raspunsulcorect";
$corect4="raspunsulcorect";
if(isset($_POST['submit']))
{
$raspuns1=$_POST['raspuns1'];
$raspuns2=$_POST['raspuns2'];
$raspuns3=$_POST['raspuns3'];
$raspuns4=$_POST['raspuns4'];
}
?>
The problem is that when I open the page, it shows me
Notice: Undefined index: raspuns1 in A:\XAMPP\htdocs\Copie\Teste\test1-geometrie.php on line 5
Notice: Undefined index: raspuns2 in A:\XAMPP\htdocs\Copie\Teste\test1-geometrie.php on line 6
Notice: Undefined index: raspuns3 in A:\XAMPP\htdocs\Copie\Teste\test1-geometrie.php on line 7
Notice: Undefined index: raspuns4 in A:\XAMPP\htdocs\Copie\Teste\test1-geometrie.php on line 8
After pressing the submit button, everything is okay, but if the page is opened the first time, this will be shown. What am I doing wrong? That first if should not let the program check the variables