I am trying to display the value from a PHP variable in the value of an HTML text input field. Currently the text input field after submit just prints the contents of the PHP script. The script is called submit_type.php
<?php
if(isset($_POST['submit'])) {
$wire_type = $_POST['wire_type_option'];
header("Location: ./guest.html");
}
else {
echo "loop";
}
?>
I have already tried the solution from the question using a PHP variable in an text input value = statement as seen in the guest.html line 39, but it doesn't seem to work
<input type="text" name="type" value="<?php echo htmlspecialchars($wire_type); ?>" />
The submit button on the main index.html page redirects you to guest.html (almost identical to the index.html file, with the exception of line 39, where the value is set)
For reference, here is guest.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>
What am I missing here? I am still new to web development, so any and all help is appreciated!
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
then the rest of your code, to see if it yields anything. – Fred -ii- Mar 31 '15 at 3:44.html
files as PHP? If not, then you can't run PHP directives. Rename it to.php
or tell Apache to treat them as PHP. Same thing goes for guest.html and any other.html
files you may be trying to run PHP directives. – Fred -ii- Mar 31 '15 at 3:45