我的密码有问题,你能帮帮我吗?首先,我想问一下用户在家里是否有充电的可能。如果他的回答是肯定的,我想运行一个文件(homechargingyes.php)与他的收费选项,我想保存他的答案在会话变量。如果他的回答是“否”,则会运行另一个文件(homechargingno.php),并且只有一条消息是可见的。下面是我的文件和代码:
主档案:
Do you have any charging possibility at household?</br>
<form method="post" action="">
<input type="radio" name="chargeathome" value="Yes">Yes
<input type="radio" name="chargeathome" value="No">No
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($_POST["submit"]) and $_POST["chargeathome"]== "Yes"){
include 'homechargingyes.php';
}elseif (isset($_POST["submit"]) and $_POST["chargeathome"]== "No" ){
include 'homechargingno.php';
}
?>homechargingyes.php:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<form action="" method="post">
<b>Type of socket:</b><input type="radio" name="typeofsockethome" value="Domestic socket 120V">Domestic socket 120V</br>
<input name="typeofsockethome" type="radio" value="Domestic socket 240V">Domestic socket 240V</br>
<input type="radio" name="typeofsockethome" value="CEE Blue">CEE Blue</br>
<input type="radio" name="typeofsockethome" value="CEE Red">CEE Red</br>
<input type="radio" name="typeofsockethome" value="Wallbox">Wallbox</br>
<b>Hours of continuous battery charge:</b> <input name="charginghourshome" type="number" min="0" max="24" value=""></br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
$_SESSION["chargeathome"]= $_POST["chargeathome"];
if (isset($_POST["submit"])){
$_SESSION["typeofsockethome"]= $_POST["typeofsockethome"];
$_SESSION["charginghourshome"]= $_POST["charginghourshome"];
}
?>
</body>
</html>和homechargingno.php:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
$_SESSION["chargeathome"]= $_POST["chargeathome"];
echo "There is no charging possibility at home.";
?>如果用户单击“否”按钮,一切都正常。但是,如果他选中“是”,在按submit之后,就会在第21行的homechargingyes.php中有一个未定义的索引:未定义的索引: typeofsockethome,在第22行的homechargingyes.php中,还有另一个未定义的索引: charginghourshome。如果我忽略这些通知并选择上面的选项之一,然后单击submit其他关于未定义索引的通知就会出现。这一次是关于我的主文件中的变量“收费”。你能理解出什么问题并帮助我吗?
发布于 2015-09-02 12:20:07
试试这个..。我浓缩了你的代码,把所有的东西都放在一页上。
以前的部分问题是页面上显示了多个表单,每个表单都询问提交按钮是否被点击了,例如:$_POST' submit‘
不需要单独的网页,并包括。
这也包括你问的results.php问题。
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php if (!isset($_POST["update"])) { // if the form has never been submitted ?>
Do you have any charging possibility at household?</br>
<form method="post" action="">
<input type="radio" name="chargeathome" value="Yes">Yes
<input type="radio" name="chargeathome" value="No">No
<input type="hidden" name="update" value="form1">
<input type="submit" name="submit" value="Submit">
</form>
<?php }
if (isset($_POST["update"]) && ($_POST["update"] == "form1") && $_POST['chargeathome'] == 'Yes'){
$_SESSION["chargeathome"] = "Yes";
?>
<form action="" method="post">
<b>Type of socket:</b><input type="radio" name="typeofsockethome" value="Domestic socket 120V">Domestic socket 120V</br>
<input name="typeofsockethome" type="radio" value="Domestic socket 240V">Domestic socket 240V</br>
<input type="radio" name="typeofsockethome" value="CEE Blue">CEE Blue</br>
<input type="radio" name="typeofsockethome" value="CEE Red">CEE Red</br>
<input type="radio" name="typeofsockethome" value="Wallbox">Wallbox</br>
<b>Hours of continuous battery charge:</b> <input name="charginghourshome" type="number" min="0" max="24" value=""></br>
<input type="hidden" name="update" value="form2">
<input type="submit" name="submit2" value="Submit">
</form>
<?php }
if (isset($_POST["update"]) && $_POST['update'] == 'form2'){
$_SESSION["typeofsockethome"]= $_POST["typeofsockethome"];
$_SESSION["charginghourshome"]= $_POST["charginghourshome"];
?>
You do have charging ability at home<br><br>
Your socket type is: <?php echo $_SESSION['typeofsockethome'] ?><br><br>
Your charging time is: <?php echo $_SESSION['charginghourshome'] ?><br><br>
<?php }
if(isset($_POST["update"]) && $_POST["chargeathome"] == "No" ){
$_SESSION["chargeathome"] = $_POST["chargeathome"];
?>
There is no charging possibility at home
<?php } ?>
</body>
希望这能有所帮助
https://stackoverflow.com/questions/32351938
复制相似问题