我试图在HTML文本输入字段的值中显示来自PHP变量的值。目前提交后的文本输入字段仅打印PHP脚本的内容。该脚本称为submit_type.phpPHP变量和HTML文本输入值
<?php
if(isset($_POST['submit'])) {
$wire_type = $_POST['wire_type_option'];
header("Location: ./guest.html");
}
else {
echo "loop";
}
?>
我已经尝试从问题Using a PHP variable in a text input value = statement 如见于guest.html线39的解决方案,但它似乎没有工作
<input type="text" name="type" value="<?php echo htmlspecialchars($wire_type); ?>" />
主要index.html页面上的提交按钮将您重定向到guest.html(几乎与index.html文件相同,除了第39行,其中值已设置)
仅供参考,以下是访客。 html
<!DOCTYPE html>
<html>Current
<head>
<title> Thermocouple Database</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<section>
<h1> Login to upload a calibration</h1>
<form>
<div class='login'><label for="username"> Username: </label></div>
<input type="text" name="username">
<div class='pass'><label for="password"> Password: </label></div>
<input type="text" name="password">
<input type="submit" value="Submit">
<br> <br> <br> <br>
</form>
</section>
<section>
<h1> Which thermocouple type do I have? </h1>
<label> My wire looks like: </label>
<form method="post" action="submit_type.php">
<select name='wire_type_option'>
<option value="J-type"> J-type </option>
<option value="K-type"> K-type </option>
<option value="T-type"> T-type </option>
<option value="E-type"> E-type </option>
</select>
<input type="submit" name="submit" value="Submit wire type">
</form>
<!-- <form method="get" action="action.php"> -->
<div id="results">
Result: <label name="result_label"> </label>
<div id="result_table">
<label> Type: </label>
<input type="text" name="type" value="<?php echo htmlspecialchars($wire_type); ?>" />
<label> Temperature Range: </label>
<input type="text" name="min_temp">
<label> - </label>
<input type="text" name="max_temp">
<br> <br> <br>
<label> Published calibration </label>
<br> <br>
<label> Voltage: </label>
<input type="text" name="in_voltage">
<label> Calibrated Temperature: </label>
<input type="text" name="out_temp">
<br> <br>
<label> Temperature: </label>
<input type="text" name="in_temp">
<label> Calibrated Voltage: </label>
<input type="text" name="out_voltage">
</div>
</div>
<!-- <input type="submit" value="Submit"> -->
<!-- </form> -->
</section>
</body>
</html>
我在这里错过了什么?我对web开发仍然陌生,所以任何和所有的帮助表示赞赏!
在打开PHP标记 (例如'<?php error_reporting(E_ALL);)后立即向文件顶部添加错误报告。 ini_set('display_errors',1);'然后你的代码的其余部分,看看它是否产生任何东西。 – 2015-03-31 03:44:57
您的页面具有html扩展名,将其更改为php,以便在将页面发送到浏览器之前执行php代码。 – jeff 2015-03-31 03:45:30
*“主index.html上的提交按钮”* - 您是否指示Apache将'.html'文件视为PHP?如果没有,那么你不能运行PHP指令。将它重命名为'.php'或告诉Apache将它们视为PHP。 guest.html和任何其他可能试图运行PHP指令的'.html'文件也是如此。 – 2015-03-31 03:45:41