gpt4 book ai didi

PHP - 无法访问已选中的复选框值

转载 作者:行者123 更新时间:2023-11-29 11:36:07 24 4
gpt4 key购买 nike

对于我的数据库项目,我正在做这个表单,用户可以选择他想要的信息,并将其显示在 html 页面上。目前我只实现遇到问题的复选框。

问题是,当我在操作页面“fe_page2.php”中检查复选框时(对于我当前的实现,我只对用户检查“位置”+“管道类型”+“金额”的情况感兴趣) ”,检查复选框是否被选中的 if 条件永远不会被达到,而是总是转到 else 条件。下面提供了代码。

这是我的基本 html 页面:

    <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>

这是 php 页面 fe_page2.php

<?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)){
.....
}

并从 html 页面中删除该值并使用以下代码:

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

但还是没有运气...任何帮助将不胜感激。

所提供的代码纯粹是我的作品,但确实包含来自下面提供的引用的代码片段:

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

最佳答案

您错过了此处的引言:

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

关于PHP - 无法访问已选中的复选框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36563024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com