
Originally Posted by
risendead
Wouldn't it be easier to just go ahead and change the form instead of switching one variable for another later or would this cause problems down the road?
You would think!!
However, the information has to be posted before you can do anything with it.
Changing the form will have little effect because the action is "hiUser.php" which means the the data in the fields within this form will carry over to the is page when you click submit.
The other alternative is to blend the php in with the form. In other words, you would have something like
PHP Code:
<?php
if isset($_POST['submit']) {//asks if the form has been submitted
$_SESSION['userName'] = $_POST['userName']; // assigns the form data to session
echo "Hello".$_SESSION['userName']; // prints value of userName
} else { //or if the form hasn't been submitted
?>
put your form here, but the action would be null (action="") which will post back to the same page.
<?php } ?>
Two jobs done in one!

Originally Posted by
risendead
I'm unsure of the newer PHP version but from what I learned so far this:
$_SESSION['userName'] = $_POST['userName'];
Means it gets (=) shouldn't it be it is equal to (==)?
Nope - this confused me to start.
If you are requesting a comparison you use a double equal
PHP Code:
<?php
if ($_SESSION['userName'] == "Administrator") {
echo "Hi Administrator";
} ?>
Similarly, you can use other characters that are doubled
PHP Code:
<?php
if ($_SESSION['userName'] == "Administrator" && $_SESSION['userType'] == "A cool Dude") {
echo "hi cool dude.";
} ?>
but in this case, you are defining a variable, so a single equal is all you need.
PHP Code:
$a = 1;
$b = 2;
$c = $a + $b;
echo $c;
For future reference, there are 3 main types of variable
$_POST (from a form)
$_GET (from the URL. Can be used when you are passing a variable in a link)
$_SESSION (duh!...what we've been talking about)