I've been working on a simple script in an effort to learn a little more about PHP. To that end I am trying to create a form handler that will echo the name of which ever user is older and I've gotten very confused and am hoping someone of you might take a look and give me some simple pointers as to what i am doing wrong. Ideally, $result will echo the name of whichever person is older.
My Submit form (0001Form.php)
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test | Form</title>
<meta name="description" content="php tutorial stuff">
<meta name="author" content="php tutorial stuff">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<script src="js/scripts.js"></script>
<form action="0001FormHandler.php" method="post">
<p> Name 1: <input type="text" name="userNameA" /> </p>
<p>Age 1: <input type="text" name="userAgeA"/></p>
<p>Your name 2: <input type="text" name="userNameB" /></p>
<p>Your age 2: <input type="text" name="userAgeB" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>
My first attempt at a form handler (0001FormHandler.php):
<?php
//Assign ages to vars for comparison from from
$varA == userAgeA;
$varB == userAgeB;
//compare vars
if ($varA >= $varB)
{$result == UserAgeA;}
else ($result == userAgeB);
//If A is older then B, use A name, else B
if ($result == UserAgeA)
{$result = userNameA;}
else ($result = userNameB);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome <?php echo $result;?></title>
<meta name="description" content="php tutorial stuff">
<meta name="author" content="php tutorial stuff">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<script src="js/scripts.js"></script>
<p>
Hello <?php echo htmlspecialchars($_POST['userNameA']); ?>.
You are <?php echo (int)$_POST['userAgeB']; ?> years old.
Hi <?php echo htmlspecialchars($_POST['userNameB']); ?>.
You are <?php echo (int)$_POST['userAgeB']; ?> years old.
</p>
</body>
</html>
My second attempt at a form handler (0001FormHandler.php):
<?php
//asign values to evaluate
$varA = ($_POST[userAgeA]);
$varB = ($_POST[userAgeB]);
//If A is Greater then B, then a else b
if ($varA >= $varB)
{$result == UserAgeA;}
else ($result == userAgeB);
//if A then UserA else User B
if ($result == UserAgeA)
{$result = userNameA;}
else ($result = userNameB);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
//Echo result name in title!
<title>Welcome <?php echo $result;?></title>
<meta name="description" content="php tutorial stuff">
<meta name="author" content="php tutorial stuff">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<script src="js/scripts.js"></script>
<p>
Hello <?php echo htmlspecialchars($_POST['userNameA']); ?>.
You are <?php echo (int)$_POST['userAgeB']; ?> years old.
Hi <?php echo htmlspecialchars($_POST['userNameB']); ?>.
You are <?php echo (int)$_POST['userAgeB']; ?> years old.
</p>
</body>
</html>
$varA == userAgeA;Assignment in PHP is$varA = userAgeA;only ONE equal sign. Do this, edit your code, and ask again.