Making a form

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
desithug
Forum Newbie
Posts: 6
Joined: Mon Aug 11, 2008 8:52 am

Making a form

Post by desithug »

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.
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: Making a form

Post by dajawu »

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.

Code: Select all

 
echo "Name: ". $_POST['name'];
echo "<br>Age: ".$_POST['age'];
 
http://us3.php.net/manual/en/function.sprintf.php
desithug
Forum Newbie
Posts: 6
Joined: Mon Aug 11, 2008 8:52 am

Re: Making a form

Post by desithug »

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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Making a form

Post by jayshields »

Does your script have a .php extension?
desithug
Forum Newbie
Posts: 6
Joined: Mon Aug 11, 2008 8:52 am

Re: Making a form

Post by desithug »

yes it does!
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: Making a form

Post by dajawu »

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:

Code: Select all

 
phpinfo();
 
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!
desithug
Forum Newbie
Posts: 6
Joined: Mon Aug 11, 2008 8:52 am

Re: Making a form

Post by desithug »

yes php works
desithug
Forum Newbie
Posts: 6
Joined: Mon Aug 11, 2008 8:52 am

Re: Making a form

Post by desithug »

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.
dajawu
Forum Commoner
Posts: 59
Joined: Fri May 23, 2008 10:16 am

Re: Making a form

Post by dajawu »

So if the code works fine on the internet, but not on your local computer (i'm guessing) then your local setup is wrong.
desithug
Forum Newbie
Posts: 6
Joined: Mon Aug 11, 2008 8:52 am

Re: Making a form

Post by desithug »

but somehow phpinfo() works as does some other codes.....
Post Reply