Not showing echo

Hello i have a problem when i try to echo $row[“sugeneruoja”]; at the end it not shows the answer it just blank maybe could help me ?

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  Mėnesinė įmoka įmoka: <input type="text" name="MonInvestment" value="0">
   <?php echo $MonInvestmentErr;?>
  <br><br>  
  Vienkartinė įmoka: <input type="text" name="Investment" value="0">
   <?php echo $InvestmentErr;?>
  <br><br>
  Norima sukaupti suma: <input type="text" name="TotalInvestmentDesire">
  <span class="error">* <?php echo $TotalInvestmentDesireErr;?></span>
  <br><br>
  <?php  
    
                          if(mysqli_num_rows($result) )  
                          {  
                               while($row = mysqli_fetch_array($result))  
                               {  
                          ?>  
                          
                          <form method="POST">
                              <select name="inv"> 
                              
                               <option><?php echo $row["rizikos_lygis"];?></option>
                               <option value=<?php echo $row["sugeneruoja"]; ?>><?php echo $row["pavadinimas"];?>&nbsp<?php echo $row["sugeneruoja"]; ?></option>
                              </select>
                              <input type="submit" name="submit" value="Apskaičiuoti">    
                          </form>
                           
                          <?php  
                               }  
                              
                          }  
             
  ?> 
  
</form>
</div>
<br>
<?php
if(isset($_POST['submit'])){
 echo $row["sugeneruoja"];
}
?>

Nested forms are invalid. The form you are outputting inside of the while(){} loop is breaking the form you are starting on the first line of the posted code. Do you in fact want one overall form (in which case you probably want just a single submit button for the whole form) or do you want a separate form per row of data? You need to define what your html markup will be and what data will be submitted, before you write any code.

Next, a select/option menu with just two choices is probably not the best User Interface (UI). Perhaps a checkbox would be more appropriate or a form per row of data with just a hidden field? Your existing usage of two option choices will cause the rizikos_lygis (level of risk) value to be submitted, because there is no value=’…’ attribute, if the second option is not selected. Your form processing code would need to detect this in order to know that nothing was chosen. You would typically use an empty value - value='' for the 1st/default choice, so that your form processing code has a specific value it can test for.

Lastly, your post method form processing code should be located above the start of the html document, it should detect if a post method form was submitted, then trim, validate, and use the submitted form data, in $_POST. Trying to use $row in your existing form processing code won’t work because after the end of the while(){} loop, $row is a false value and $row["sugeneruoja"] simply doesn’t exist (you would be getting a php error if your error settings are setup to report and display all php errors.)

Sponsor our Newsletter | Privacy Policy | Terms of Service