Making a form
Moderator: General Moderators
Making a form
hey guys,
I am really new at programming with php. I was having a problem with getting a form to output as expected.
It is supposed to take in the name and age of the person and then return it.
html form:
<html>
<head>
<title> a html form</title>
</head>
<body>
<form action="action.php" method="POST">
<p>NAme<input type="text" name="name"/></p>
<p>AGe<input type="text" name="age"/></p>
<p><input type="submit" value="submit"/></p>
</form>
</body>
</html>
php code > action.php
<?php
printf("name<br/>", $_POST["name"]);
printf("age<br/>", $_POST["age"]);
?>
what might be the problem???
thanks in advance.
I am really new at programming with php. I was having a problem with getting a form to output as expected.
It is supposed to take in the name and age of the person and then return it.
html form:
<html>
<head>
<title> a html form</title>
</head>
<body>
<form action="action.php" method="POST">
<p>NAme<input type="text" name="name"/></p>
<p>AGe<input type="text" name="age"/></p>
<p><input type="submit" value="submit"/></p>
</form>
</body>
</html>
php code > action.php
<?php
printf("name<br/>", $_POST["name"]);
printf("age<br/>", $_POST["age"]);
?>
what might be the problem???
thanks in advance.
Re: Making a form
Your not using printf correctly. I will put a link at the bottom to the function sprintf you can read it and figure it out. But to fix your problem for now use echo its better suited for displaying a variable like this in my opinion.
http://us3.php.net/manual/en/function.sprintf.php
Code: Select all
echo "Name: ". $_POST['name'];
echo "<br>Age: ".$_POST['age'];
Re: Making a form
hey dajawu,
thanks for the response. I put in the code you posted and my new action.php file looks like:
<?php
echo "Name: ". $_POST['name'];
echo "<br>Age: ".$_POST['age'];
?>
however it still doesnt give the output. This is what it is displaying on the page once i submit the form.
-------------------------------
Age: ".$_POST['age']; ?>
-------------------------------
I just dont get it.
Rudy
thanks for the response. I put in the code you posted and my new action.php file looks like:
<?php
echo "Name: ". $_POST['name'];
echo "<br>Age: ".$_POST['age'];
?>
however it still doesnt give the output. This is what it is displaying on the page once i submit the form.
-------------------------------
Age: ".$_POST['age']; ?>
-------------------------------
I just dont get it.
Rudy
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: Making a form
Does your script have a .php extension?
Re: Making a form
Your server might not support PHP, are you hosting this on the internet or on your computer? To see if PHP works make a PHP page and call it test.php and put this code in it:
Then open up that page, if PHP is configured properly you should get a very big page full of info about your setup, if it doesn't work something is wrong with the setup!
Code: Select all
phpinfo();
Re: Making a form
phpinfo() works, however my code doesnt for some strange reason...it works when i am hosting it on the internet...any explanations, things that i might need to do.
Re: Making a form
So if the code works fine on the internet, but not on your local computer (i'm guessing) then your local setup is wrong.
Re: Making a form
but somehow phpinfo() works as does some other codes.....