need some help (forms involved)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mabufo
Forum Commoner
Posts: 81
Joined: Thu Jul 10, 2003 11:11 pm
Location: Orland Park, IL
Contact:

need some help (forms involved)

Post by mabufo »

Hi, I've just recently taken up php again. I have a problem. I have two pages that work together - one displays some variables and the other processes the input of a form that I have on the first page. You may have noticed that I have been following along with the php.net tutorial - but I've done my best to learn as much as I could while moving through it. When I push the submit button on the form, I get this error:

Code: Select all

Parse error: parse error, unexpected T_VARIABLE, expecting '(' in /home/mabufo/www/action.php on line 10
Here is my first page (index.php)

Code: Select all

<html>
<head>
<title>Welcome to Line Break</title>
</head>

<body>
<?php echo '<p>Hello everyone!</p>'; ?>
<br />
<?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') == False) { 
	echo 'You are not using IE.';
	}
?> 

<?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== False) {
	echo 'You are using IE.';
	}
?>
<br />
<?php echo 'You are using: ';
	echo $_SERVER['HTTP_USER_AGENT'];
?> 
Here is a little thing for you to fill out...<br />

<form action="action.php" method="post">
	<p>Name: <input type="text" name="Handle" /></p>
	<p>Age: <input type="text" name="yearsOld" /></p>
	<p>Browser: <input type="text" name="browser" /></p>
	<p> <input type="submit"/></p>
</form>


</body>
</html>
Here is the second page (action.php)

Code: Select all

<html>
<head>
<title>Form Results.</title>
</head>
<body>
<br />

You're name is: <?php echo $_POST['handle']; ?> 

<?php if $_POST['handle'] == 'matt' {
	echo 'Hey, my name is matt too! <br />'
	}
?>

<br />
<br />

You are <?php echo $_POST['yearsOld']; ?> years of age.<br />


You said you are using: <?php echo $_POST['browser']; ?>

<?php if (strpos($_SERVER['HTTP_USER_AGENT'], $_POST['browser]) == True {
	echo 'You are using your communicated browser. <br />';

} else {

	echo 'You lied! You are using: ';
	echo $_SERVER['HTTP_USER_AGENT']; 
}<br />


</body>
</html>
Could you guys help me sort out that nasty error I've been getting? I really am not sure what an unexpected T_Variable is... though I know it has somethign to do with a form value. Also, I would apprechiate it if you all could point out logical flaws, or inncorrect structure within my code. Thank you!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You're missing parens on the if() in action.php
User avatar
mabufo
Forum Commoner
Posts: 81
Joined: Thu Jul 10, 2003 11:11 pm
Location: Orland Park, IL
Contact:

Post by mabufo »

ok, Along with the missing parens - I have gone in and fixed everything else that has been missing.

The problem now - is that On the action.php page, the user's name is not being displayed... Which in turn is stopping the page from printing: 'Hey, my name is matt too! <br />' when I enter 'matt' as the name. Am I calling the variable properly?

Also, if I wanted to do this:

Code: Select all

<?php echo 'hello'; 
echo $_POST['name']; ?>
How would I do that on a single line?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Variables and array element names are case sensitive. "handle" and "Handle" are not the same.
User avatar
mabufo
Forum Commoner
Posts: 81
Joined: Thu Jul 10, 2003 11:11 pm
Location: Orland Park, IL
Contact:

Post by mabufo »

What is wrong with this line?

Code: Select all

<?php echo "You are $_POST['yearsOld'] years of age.";
I get this error that points me to line 18 - which is that line...

Code: Select all

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/mabufo/www/action.php on line 18
That error leads me to believe I am trying to print the variable incorrectly in that line. How do I fix it while keeping everythign on the same line?
Post Reply