Page 1 of 1
Scripting Error
Posted: Tue Aug 19, 2003 3:35 pm
by skwilliams
I am very new to PHP and am studying the PHP manual. I'm stumped on an example that I tried.
I created a php page called form.php. Here's the HTML
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="action.php" method="POST">
Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
<input type="Submit">
</form>
</body>
</html>
I also created a page called action.php and it's script.
<html>
<head>
<title>Action</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Hi <?php echo $_POST["name"]; ?>
You are <?php echo $_POST["age"]; ?> years old.
</body>
I can fill out the form fine and submit it. But the resulting action.php page displays:
Hi You are years old.
It seems to be missing the data that was just entered.
Is there a problem with my script?
Posted: Tue Aug 19, 2003 5:45 pm
by qads
your code is fine, you prolly got a older version of php, try this in action.php page
Code: Select all
<html>
<head>
<title>Action</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Hi <?php $HTTP_POST_VARSї'name']; ?>
You are <?php $HTTP_POST_VARSї'age']; ?> years old.
</body>
Re: Scripting Error
Posted: Tue Aug 19, 2003 7:25 pm
by Bongulim
skwilliams wrote: Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
I'm not sure this is going to solve your problem, but I'd suggest removing the / from the end of the tags:
Code: Select all
Your name: <input type="text" name="name">
Your age: <input type="text" name="age">
Posted: Tue Aug 19, 2003 7:37 pm
by qartis
Nope, he's just following (more) proper XHTML standards.
Specifically, the fact that all html tags *should* have end tags. In the case of <br>, <input>, <img>, et cetera, one simply puts /> to end it, for example
Code: Select all
<br />
<img src=source.gif />
<input type=crash />
It's not necessary, but if you're anal retentive about your html, it's a good standard to follow.
Posted: Wed Aug 20, 2003 9:14 am
by skwilliams
I tried changing the code. It still gives me the same problem.
I'm running Apache on a Red Hat 6.2 platform with PHP4.
Posted: Wed Aug 20, 2003 9:34 am
by like_duh44
Your problem is with your echo's:
Code: Select all
<body>
Hi <?php echo $_POSTї"name"]; ?>
You are <?php echo $_POSTї"age"]; ?> years old.
</body>
It should be something like this:
Code: Select all
<body>
<?php
$name = $_POST['name'];
$age = $_POST['age'];
echo "Hi $name.";
echo "You are $age years old";
?>
</body>
Your problem was that you didnt have the "" around the echo. But you need to set $name and $age since you cant use $_POST['xxx'] because of the ''. It should work now
Posted: Wed Aug 20, 2003 9:45 am
by trollll
Echos generally work fine printing things like
for me. I haven't noticed any installations (Linux, PC, Mac) that have really complained about it.
Skwilliams, if you put in a line saying
does the array have anything inside of it at all? I use that a lot to just check form posts.
Posted: Wed Aug 20, 2003 9:47 am
by skwilliams
Thanks for your response.
I copied the script from your reply, but am still getting the same problem.
Posted: Wed Aug 20, 2003 9:52 am
by greenhorn666
Could you like tell me what this gives out as your action.php script
Code: Select all
<pre>
<?
if(isset($_POST)) {
echo "POSTED VALUES:\n";
print_r($_POST);
}
if(isset($_GET)) {
echo "GET VALUES:\n";
print_r($_GET);
}
?>
</pre>
Posted: Wed Aug 20, 2003 9:57 am
by trollll
So it just prints out "Array ( )" then?
Hmmm... Try changing the method to GET in form.php and variable calls to $_GET["name"] and $_GET"age"] in action.php... This way you should see the info submitted in the URL and we'll know that the form sent it, at least.
We'll get you there, one step at a time!

Posted: Wed Aug 20, 2003 9:57 am
by like_duh44
There are 2 things you should try. First, on the action.php page, hit ctrl + F5 to make sure the page is reloaded completely. If that doesnt work, you should try this. Although it *shouldnt* make a differnence:
Code: Select all
<?php
echo "<form method="GET" action="action.php"/>\n";
echo "Name: <input type="text" name="name"/><br/>";
echo "Age: <input type="text" name="age"/><br/>";
echo "<input type="submit"></form>";
?>
Then have your action.php page have this:
Code: Select all
<?php
$name = $_GET['name'];
$age = $_GET['age'];
echo "Hi, $name. You are $age years old!";
?>
Posted: Wed Aug 20, 2003 9:59 am
by like_duh44
LOL trolll, on the same wavelength huh?
Posted: Wed Aug 20, 2003 10:45 am
by skwilliams
Here is what displays on the action.php page once I enter a name and age and click Submit on form.php.
Hi, . You are years old!
Posted: Wed Aug 20, 2003 11:41 am
by skwilliams
It was a problem with $HTTP_POST_VARS
It works fine now.
Thanks for all your help!