pythonic pythonic - 4 months ago 9
HTML Question

PHP complains that variables are undefined

So, I have the following code. When I execute it, the start_exp.php page complains that variables YourEMail and InputFile are undefined. Apparently, the code seems right. Any idea what mistake am I doing here?

index.php

<html>
<head>
<meta charset="utf-8">
<title>Start page</title>
</head>

<link href="styles/style.css" rel="stylesheet" type="text/css">

<body style="height: 100vh; width: 100vw">
<h1>Start page</h1>
<form action="start_exp.php" method=post>
Your e-mail: <br> <input type="text" name="YourEMail">
<br /> Input file name: <br /> <input type="text" name="InputFile">
<input type="submit" name="submit" value="Start experiment">
</form>
</body>
</html>


start_exp.php

<html>

<head>
<title>Start experiment</title>
</head>

<?php
// Capture the values posted to this php program from the text fields
// which were named 'YourEMail' and 'InputFile' respectively
$YourName = $_REQUEST['YourEMail'] ;
$FavoriteWord = $_REQUEST['InputFile'] ;
?>

<body bgcolor="#FFFFFF" text="#000000">
<p> Hi <?php print $YourEMail; ?>
<p> <b> <?php print $InputFile; ?></b>
<p>The experiment has been started. You'll receive an e-mail when it is finished.
</body>

</html>

Answer

You should echo the variable names not Input field names.

<p> Hi <?php print $YourName; ?> 
<p> <b> <?php print $FavoriteWord; ?></b>
Comments