Page 1 of 1

Making a form

Posted: Mon Aug 11, 2008 8:58 am
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.

Re: Making a form

Posted: Mon Aug 11, 2008 9:07 am
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

Re: Making a form

Posted: Mon Aug 11, 2008 9:22 am
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

Re: Making a form

Posted: Mon Aug 11, 2008 9:28 am
by jayshields
Does your script have a .php extension?

Re: Making a form

Posted: Mon Aug 11, 2008 10:03 am
by desithug
yes it does!

Re: Making a form

Posted: Mon Aug 11, 2008 10:08 am
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!

Re: Making a form

Posted: Mon Aug 11, 2008 10:20 am
by desithug
yes php works

Re: Making a form

Posted: Mon Aug 11, 2008 10:45 am
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.

Re: Making a form

Posted: Mon Aug 11, 2008 10:53 am
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.

Re: Making a form

Posted: Mon Aug 11, 2008 11:44 am
by desithug
but somehow phpinfo() works as does some other codes.....