Scripting Error
Moderator: General Moderators
-
skwilliams
- Forum Newbie
- Posts: 5
- Joined: Tue Aug 19, 2003 3:35 pm
Scripting Error
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?
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?
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
I'm not sure this is going to solve your problem, but I'd suggest removing the / from the end of the tags:skwilliams wrote: Your name: <input type="text" name="name" />
Your age: <input type="text" name="age" />
Code: Select all
Your name: <input type="text" name="name">
Your age: <input type="text" name="age">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
It's not necessary, but if you're anal retentive about your html, it's a good standard to follow.
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 />-
skwilliams
- Forum Newbie
- Posts: 5
- Joined: Tue Aug 19, 2003 3:35 pm
-
like_duh44
- Forum Commoner
- Posts: 63
- Joined: Sat Jul 26, 2003 6:57 pm
Your problem is with your echo's:
It should be something like this:
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
Code: Select all
<body>
Hi <?php echo $_POSTї"name"]; ?>
You are <?php echo $_POSTї"age"]; ?> years old.
</body>Code: Select all
<body>
<?php
$name = $_POST['name'];
$age = $_POST['age'];
echo "Hi $name.";
echo "You are $age years old";
?>
</body>- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
Echos generally work fine printing things likefor 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.
Code: Select all
echo $_POST["one"];Skwilliams, if you put in a line saying
Code: Select all
print_r($_POST);-
skwilliams
- Forum Newbie
- Posts: 5
- Joined: Tue Aug 19, 2003 3:35 pm
- greenhorn666
- Forum Commoner
- Posts: 87
- Joined: Thu Aug 14, 2003 7:14 am
- Location: Brussels, Belgium
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>- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
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!
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!
-
like_duh44
- Forum Commoner
- Posts: 63
- Joined: Sat Jul 26, 2003 6:57 pm
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:
Then have your action.php page have this:
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>";
?>Code: Select all
<?php
$name = $_GET['name'];
$age = $_GET['age'];
echo "Hi, $name. You are $age years old!";
?>-
like_duh44
- Forum Commoner
- Posts: 63
- Joined: Sat Jul 26, 2003 6:57 pm
-
skwilliams
- Forum Newbie
- Posts: 5
- Joined: Tue Aug 19, 2003 3:35 pm
-
skwilliams
- Forum Newbie
- Posts: 5
- Joined: Tue Aug 19, 2003 3:35 pm