2016-04-12 10 views
0

私のデータベースプロジェクトでは、ユーザーが希望する情報を選択してHTMLページに表示するこのフォームを実行しています。当分の間、私は問題に遭遇しているチェックボックスだけを実装しています。PHP - チェックされたチェックボックスの値にアクセスできない

問題は、自分のアクションページ「fe_page2」のチェックボックスをチェックすると(現在の実装では、ユーザーが「場所」+「パイプタイプ」+「金額」をチェックする場合のみです) php "では、チェックボックスがチェックされているかどうかをチェックするif条件は、決してelse条件になりません。コードは以下の通りです。

これが私の基本的なHTMLページです:これは

<?php 

require('dbconf.inc'); 

db_connect(); 

print"<pre>"; 
print_r($_POST); 
print"</pre>"; 

$pipelocation = $_POST[pipelocation]; 
$pipetype = $_POST[Pipe-Type]; 
$pipeamount = $_POST[amount]; 

if($pipelocation=='value1' && $pipetype == 'value2' && $pipeamount == 'value3'){ 

    $qrySel="SELECT `Pipe_ID`, `Location`, `Amount`, `PipeType` FROM pipe order by Pipe_ID desc"; 
    $resSel = mysql_query($qrySel); 

    if($resSel){ 

     while($rowpipe = mysql_fetch_array($resSel, MYSQL_ASSOC)){ 
      echo "Pipe ID:{$rowpipe['Pipe_ID']} <br> ". 
      "Location: {$rowpipe['Location']} <br> ". 
      "Amount: {$rowpipe['Amount']} <br>". 
      "PipeType: {$rowpipe['PipeType']} <br>". 
      "--------------------------------<br>"; 
     } 

     echo "Fetched Data Successfully!\n";  

    } 
} 
else{ 
    echo"never went in!"; 
} 

db_close(); 



?> 

は私が

if(isset($pipelocation) && isset($pipetype) && isset($pipeamount)){ 
    ..... 
} 

や削除などの異なるものを試してみましたfe_page2.php PHPのページがある

<html> 
<head> 
    <title>Flow Element</title> 
</head> 
<body> 
    <h1 style="margin-left: 450px">Retrieve Flow Element Information</h1> 
    <hr> 
    <form action="fe_page2.php" method="post"> 
    All Times: 
    <input type="checkbox" name="alltimes" onchange="changeFields()"><br><br> 
    Start Date: 
    <input type="date" name="startdate" id="startdate"> 
    Start Time: 
    <input type="time" name="starttime" id="starttime"><br><br> 
    Same Time: 
    <input type="checkbox" name="sametime" id = "sametime" onchange="sameFields()"><br><br> 
    End Date: 
    <input type="date" name="enddate" id="enddate"> 
    End Time: 
    <input type="time" name="endtime" id="endtime"><br><br> 

    <h3> Select fields of output</h3> 
    <hr> 

    Pipe Key: <input type="text" name="pipepirmary" id="pipekey"><br> 

    <input type="checkbox" name="pipelocation" id="pipeLocation" value="value1" > 
    Location<br> 

    <input type="checkbox" name="Pipe-Type" id="pipetype" value="value2"> 
    Pipe-Type<br> 

    <input type="checkbox" name="amount" id="amount" value="value3"> 
    Amount<br><br> 

    Flow Element:<input type="text" name="fepirmarykey" id="fekey"/><br> 

    <input type="checkbox" name="flow" id="flo"> 
    Flow<br> 

    <input type="checkbox" name="temperature" id="temp"> 
    Temperature<br> 

    <input type="checkbox" name="pressure" id="pres"> 
    Pressure<br><br> 

    <input type="submit"> 
</form> 
    <script> 
     function changeFields() { 

      if(document.getElementById("startdate").disabled == false){ 
       document.getElementById("startdate").disabled = true; 
       document.getElementById("starttime").disabled = true; 
       document.getElementById("enddate").disabled = true; 
       document.getElementById("endtime").disabled = true; 
       document.getElementById("sametime").disabled = true; 
       if(document.getElementById("sametime").checked = true){ 
        document.getElementById("sametime").checked = false; 
        } 
       document.getElementById("startdate").value = null; 
       document.getElementById("starttime").value = null; 
       document.getElementById("enddate").value = null; 
       document.getElementById("endtime").value = null; 
      } 
      else{ 
       document.getElementById("startdate").disabled = false; 
       document.getElementById("starttime").disabled = false; 
       document.getElementById("enddate").disabled = false; 
       document.getElementById("endtime").disabled = false; 
       document.getElementById("sametime").disabled = false; 
      } 

     } 
     function sameFields() { 
      if(document.getElementById("enddate").disabled == false){ 
       document.getElementById("enddate").disabled = true; 
       document.getElementById("endtime").disabled = true; 
       document.getElementById("enddate").value = null; 
       document.getElementById("endtime").value = null; 
      } 
      else{ 
       document.getElementById("enddate").disabled = false; 
       document.getElementById("endtime").disabled = false; 
      } 
     } 
    </script> 

</body> 
</html> 

次のコードを使用してください:

if($pipelocation == 'on' && $pipetype == 'on' && $pipeamount == 'on'){ 
       ... 
    } 

しかし、まだ運がありません... 助けていただければ幸いです。

提示されたコードは純粋に私の仕事ですが、以下に参照するから来ているコードの一部含んでいます:あなたがここに引用を逃した

https://www.youtube.com/watch?v=LZtXYa9eGGw

答えて

1

$pipelocation = $_POST['pipelocation']; 
$pipetype = $_POST['Pipe-Type']; 
$pipeamount = $_POST['amount']; 
+1

ああ、神様を、 ありがとうございました。今はそんなに馬鹿だと感じる。もう一度ありがとう! –

+0

いつか起こります。何も心配する必要はありません。 –

関連する問題