Jump to content

How to echo option i selected, because right now it shows blank


Lukeishen

Recommended Posts

<?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  
                               }  
                          }  
  ?> 
<?php
if(isset($_POST['submit'])){
 echo $row["sugeneruoja"];
}
?>

Edited by Lukeishen
Link to comment
Share on other sites

  • Lukeishen changed the title to How to echo option i selected, because right now it shows blank

You structure looks wrong to me. 

You have multiple form elements, each of which contains one select element with two option elements. 

I would expect there to be one form element, which contains one select element, which contains one or more option elements. 

echo( '<form method="POST">' ); 
echo( '<select name="inv">' );
if( mysqli_num_rows($result) ) 
{  
  echo( '<option>' . $row["rizikos_lygis"] . '</option>' );
  while( $row = mysqli_fetch_array($result) )  
  {  
    printf( '<option value=\'%s\'>%s&nbsp;%s</option>'
      , $row["sugeneruoja"]
      , $row["pavadinimas"] 
      , $row["sugeneruoja"] 
      );
  }
}
echo( '</select>' ); 
echo( '<input type="submit" name="submit" value="Apskaičiuoti">' ); 
echo( '</form>' ); 

Regards, 
   Phill  W.

 

  • Thanks 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.