Page 1 of 1

New to PHP

Posted: Wed Nov 26, 2003 11:02 am
by Rmias
Hi Can someone tell me on how to pass form values to a php page and display those values. As I am new to php I tried every possible way to do this without a success. Am I missing something or need to configure php to read the variables. here are the create form.php and processform.php.
---------------------------------------------------------------------------
<html>
<head>
<title>Create a form</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<form action="processForm.php" method="get">
Enter your name :
<input type="text" name="username"><br>
Where do you live :
<input type="text" name="region"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
---------------------------------------------------------------------------
<html>
<head>
<title>Process Form Data</title>
</head>
<body>
<h3>Your information has been processed.</h3>
<?php
print "Thank you $username<br>";
Print "You live in :$region";
?>
</body>
</html>

I am using PHP 4.2.3 on Apache web server

Thank you

Posted: Wed Nov 26, 2003 11:09 am
by JayBird
read this

viewtopic.php?t=511

and your questions will be answered.

basically you need to do this

Code: Select all

print "Thank you ".$_GET['username']."<br>";

Mark

Posted: Wed Nov 26, 2003 11:16 am
by dull1554
try this

form.php <---No need for this to be a php file, it can be plain html.

Code: Select all

<html>
<head>
<title>Create a form</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<form action="processForm.php" method="post"//i changed your method to post from get>
Enter your name :
<input type="text" name="username"><br>
Where do you live :
<input type="text" name="region"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
heres processform.php

Code: Select all

<html>
<head>
<title>Process Form Data</title>
</head>
<body>
<h3>Your information has been processed.</h3>
<?php
$username = $_POST['username'];//you have to define the $vars as info thats gonna get pulled out of the form
$region = $_POST['region'];
print "Thank you $username<br>";
Print "You live in :$region";
?>
</body>
</html>

Posted: Wed Nov 26, 2003 11:17 am
by dull1554

Code: Select all

<html>
<head>
<title>Process Form Data</title>
</head>
<body>
<h3>Your information has been processed.</h3>
<?php
$username = $_POST['username'];//you have to define the $vars as info thats gonna get pulled out of the form
$region = $_POST['region'];
print "Thank you $username<br>";
Print "You live in :$region";

</body>
</html>
sorry i forgot to close the syntax highlighter tag

Posted: Wed Nov 26, 2003 11:47 am
by d3ad1ysp0rk
you can edit post you know? ;)

Posted: Wed Nov 26, 2003 12:22 pm
by johnperkins21
I'm also new to php and would like some clarification. I have done something similar to what rmias is talking about. I used the Post method, but I did not use $_POST['variable'] and my code still worked. Is there a reason to use the $_POST that I should be aware of?

Here is my code:

Form page

Code: Select all

<html>
<head>
<title>This is the input page</title>
</head>

<body bgcolor = #ffffff>

<h2>This is a test</h2>

<form action = "test.php" method = "post">

Salesperson: <input type="text" name="salesperson">
<p>
Cost of Car: <input type="text" name="cost">
<p>
<input type="submit" name="submit" value="Calculate commission">
</form>
</body>
</html>
Here is the php:

Code: Select all

<html>
<head>
<title>This is a test page.</title>
</head>

<body bgcolor = #ffffff>
<?php
$commission_percent = .2;

function Commission ($cost, $commission_percent, $salesperson) &#123;
	$commission_total = ($cost * $commission_percent);
	
	echo "$salesperson has sold a car for \$$cost."; 
	echo "<p>";
	echo "$salesperson's commission is \$$commission_total";
	
&#125;

commission ($cost, $commission_percent, $salesperson);
?>
</body>
</html>
It's just something I threw together as a test. I would much prefer to write proper code than just trash that works.

Posted: Wed Nov 26, 2003 12:55 pm
by infolock
may want to view :

viewtopic.php?t=511

Posted: Wed Nov 26, 2003 12:57 pm
by Rmias
Thank you very much for all your help. The php displays the result I wanted.

Rmias