Dropdown help

I am making a page for email where user selects data from a drop down list. I need to add 4 entries (email,server, type & port) to a file.
I have a submit after 1st two entries then i use java to run the remaining part.

Software works partly fine (it writes all data required), The first two entries are added correctly to file, it enters a blank line (not wanted) plus port ( not wanted) correctly adds type an additional blank line (not required) then correctly adds the port data.

Is an alternative method possible ?

div>
 <form method='GET'>
  <label for='type'><b>Receive  Type:</b></label>
  <select name ='type' id='type' onchange="mytype()">
  <option value='' selected>Select</option>
  <option value='POP' >POP </option>
  <option value='IMAP'>IMAP</option>
  </select>
  
  <script> 
  function mytype()
  {
  
          var x = document.getElementById("type").value;
          window.location.href = "mail_recv.php?Type="+x ;
 }
  </script>
  <?php
  $type=$_GET['Type'];
 fwrite($mail, $type);
?>
</div>
<div>
<form method='GET'>
 <label for='port'><b>Receive Port:</b></label>
 <select name ='port' id='port' onchange='myport()'>
 
 <?php
 
 if($type==='POP') {
 echo "<option value='' selected>Select</option>";
 echo "<option value=Default:110>Default:110</option>";
 echo "<option value=TLS:995>TLS:995</option>";
 echo "</select>";
 }elseif($type==='IMAP') {
 echo "<option value='' selected>Select</option>";
 echo "<option value=Default:143>Default:143</option>";
 echo "<option value=TLS:993>TLS:993</option>";
 echo "</select>";
 echo "</div>";
 }else {
 echo "<option value='' selected>Select</option>";
 }
?>
<script> 
function myport()
{
         var y = document.getElementById("port").value;
         window.location.href = "mail_recv.php?Port="+y ;
}
 </script>
 
 <?php
 $port=$_GET['Port'];
 fwrite($mail, $port);
 fclose($mail);


Sorry first part got left out!

 4 <!DOCTYPE html>
  5 <html lang=eng>
  6 <title> HTML Form </title>
  7 <body>
  8 <div>
  9 <form  method="post">
 10 <label for='email'><b> Enter Email:</b></label>
 11 <input type='text' placeholder='[email protected]' name='email'>
 12 <input type=hidden value='email'>
 13 </div>
 14 <div>
 15 <form  method="post">
 16 <label for='server'><b> Enter Server:</b></label>
 17 <input type='text' placeholder='mail.xxx.com' name='server'>
 18 </div>
 19 
 20 <input type= submit value=submit  name=submit>
 21 
 22 
 23 <?php
 24 
 25 $email=$_POST['email'];
 26 $server=$_POST['server'];
 27 $mail = fopen("data.txt", "a");
 28 fwrite($mail, $email );
 29 fwrite($mail, "\r\n" );
 30 fwrite($mail, $server);
 31 fwrite($mail, "\r\n" );
 32 
 33 ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service