-
<html>
-
<head>
-
<title> then you must be...</title>
-
</head>
-
-
<body>
-
-
-
<h1>Hi User</h1>
-
<h3> php program that recieves a value from "index.html"</h3>
-
-
<?php
-
$userName = trim($_POST['userName']);
-
echo "<h3> Hello " . $userName . "!</h3>";
-
-
?>
-
-
</body>
-
</html>
-
-
Try the above. The changes I make are as follows:
1) use of <?php instead of <? as PHP tag.
2) echo instead of print. Maybe print works fine, I just never used it :)
3) I broke up the argument to the echo statement to three pieces using the string concatenation symbol which is a period. I did this because you have a ! just after the PHP variable name. This is probably no problem, but I do this just to make sure the line is handled correctly by PHP. There are many ways of writing this line, but what I did above should work.
4) You need to retrieve the value of userName from the $_POST array. Note that the $_POST array may be case sensitive. I use Linux, which definitely is case sensitive, so in this case "userName" would be present but "username" would not be! I am not sure about PHP on Windows, whether that is case sensitive, but it is best to keep case sensitivity in case you ever need to port your scripts.
If the above does not work, then you need to examine your $_POST array and see if it is present and correct. To do this, try putting this statement in the script above, after the <body> tag:
echo "<pre>";
print_r($_POST);
echo "</pre>";
That should print a listing of your $_POST array. If it is empty or you do not see the entry for 'userName', then you need to inspect your php configuration to see why. Also make sure that the page that calls this script (the one the user submits) is properly set up such that the submit button and the userName input field are contained within the same form tags (if you put two sets of form tags on your page or made some mistake here, you may not get the input values to your $_POST correctly.