2016-07-04 2 views
0

모든 PHP 전문가 : 초보자입니다. 나는이 참조 전극 변환기가 있습니다드롭 다운 메뉴가 이상합니다.

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Referance Electrode Converter</title> 
     <link rel="stylesheet" href="css/style.css"> 
    </head> 
    <body> 
     <h1>Referance Electrode Converter</h1> 
     <h6>After Pressing Convert The Dropdown Goes Back to It's Defaults</h6> 
     <form action="index.php" method="get"> 
      <input type="text" name="input" placeholder="Enter Amount"></input> 
      <select name="dropdown"> 
       <option value="SHE" selected><sub>SHE</sub></option> 
       <option value="SCE"><sub>SCE</sub></option> 
       <option value="AG"><sub>Ag/AgCl</sub></option> 
       <option value="MSE">MSE</option> 
       <option value="CSE">CSE</option> 
      </select> 
      <br /> 
      <?php 

$cc_input = $_GET['input']; 
$cc_dropdown = $_GET['dropdown']; 
$cc_odropdown = $_GET['odropdown']; 

if(isset($_GET['sbmt'])) 
{ 
    if($cc_dropdown == 'SHE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input + 0.2415 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.222 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.615 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input - 0.318 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
    elseif($cc_dropdown == 'SCE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input - 0.2415 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.0195 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.3735 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input - 0.765 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 

    } 
    elseif($cc_dropdown == 'AG') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input - 0.222 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input - 0.0195; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.393 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input - 0.096 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
    elseif($cc_dropdown == 'MSE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input + 0.615 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input + 0.3735 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.393 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input + 0.297 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
    elseif($cc_dropdown == 'CSE') { 
     if($cc_odropdown == 'SHE') { 
      $output = $cc_input + 0.318 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'SCE') { 
      $output = $cc_input + 0.0765 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'AG') { 
      $output = $cc_input + 0.096 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'MSE') { 
      $output = $cc_input - 0.297 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } elseif($cc_odropdown == 'CSE') { 
      $output = $cc_input * 1 . "V"; 
      echo "<input type='text' value='$output' disabled/>"; 
     } 
    } 
} 
      ?> 
      <select name="odropdown"> 
       <option value="SHE"><sub>SHE</sub></option> 
       <option value="SCE" selected><sub>SCE</sub></option> 
       <option value="AG"><sub>Ag/AgCl</sub></option> 
       <option value="MSE">MSE</option> 
       <option value="CSE">CSE</option> 
      </select> 
      <br /> 
      <input type="submit" name="sbmt" value="Convert!"></input> 
     </form> 
    </body> 
</html> 

이상한 것은 내가 클릭 할 때이다 "변환"드롭 다운 메뉴가 다시 "선택"에 상관없이 HTML로 돌아가 변수였다. 이 문제를 해결하려면 어떻게해야합니까?

감사 -Lorelo

+0

당신이 참조 전극이 무엇인지 이해할 필요가 없습니다. 통화로 생각하십시오. – Lorelo

+1

두 번째 방법으로 "참조"를 철자가 잘못 입력했습니다 ... –

+0

오, 감사합니다 ...... 지금 기분이 좋지 않습니다. – Lorelo

답변

2

확인이 내 서버에서만 문제가 있는지 확실하지 않습니다,하지만 난 정의되지 않은 GET 요청 변수를 얻기 위해 시도 할 때이 오류를 던진, 그래서 이런 짓을 :

if(isset($_GET['input'])) $cc_input = $_GET['input']; 
if(isset($_GET['dropdown'])) $cc_dropdown = $_GET['dropdown']; 
if(isset($_GET['odropdown'])) $cc_odropdown = $_GET['odropdown']; 

어쨌든 원래 문제를 해결하려면 $ cc_dropdown 및 $ cc_odropdown 값이 무엇인지 확인해야합니다. 그것에 따라, "selected"속성을 어디에 에코할지 결정해야합니다.

UPDATE 여기

내가 무슨 짓을했는지 :

... 
    <body> 
    <?php 

if(isset($_GET['input'])) $cc_input = $_GET['input']; 
if(isset($_GET['dropdown'])) $cc_dropdown = $_GET['dropdown']; 
if(isset($_GET['odropdown'])) $cc_odropdown = $_GET['odropdown']; 

    ?> 
     <h1>Referance Electrode Converter</h1> 
     <h6>After Pressing Convert The Dropdown Goes Back to It's Defaults</h6> 
     <form action="index.php" method="get"> 
      <input type="text" name="input" placeholder="Enter Amount"></input> 
      <select name="dropdown"> 
      <?php if(!isset($_GET['sbmt'])): ?> 
       <option value="SHE" selected><sub>SHE</sub></option> 
       <option value="SCE"><sub>SCE</sub></option> 
       <option value="AG"><sub>Ag/AgCl</sub></option> 
       <option value="MSE">MSE</option> 
       <option value="CSE">CSE</option> 
      <?php else: ?> 
       <option value="SHE" <?php if($cc_dropdown=="SHE") echo "selected"; ?> ><sub>SHE</sub></option> 
       <option value="SCE" <?php if($cc_dropdown=="SCE") echo "selected"; ?> ><sub>SCE</sub></option> 
       <option value="AG" <?php if($cc_dropdown=="AG") echo "selected"; ?> ><sub>Ag/AgCl</sub></option> 
       <option value="MSE" <?php if($cc_dropdown=="MSE") echo "selected"; ?> >MSE</option> 
       <option value="CSE" <?php if($cc_dropdown=="CSE") echo "selected"; ?> >CSE</option> 
      <?php endif; ?> 
      </select> 
      <br /> 
      <?php 

if(isset($_GET['sbmt'])) 
{ 
     ... 

업데이트 2

난 당신이 또한 다른 드롭 다운 목록은이 작업을 수행해야 함을 언급하는 것을 잊었다. 이것은 상단의 것입니다. 걱정하지 마라. 그것은 유사하다.

+0

전용 너에게. 오류가 없습니다. – Lorelo

+0

PHP 7 또는 5를 사용합니까? – Lorelo

+0

이것은 답변이며, 동일한 작업을하고있었습니다 – Nick

관련 문제