New to PHP
Moderator: General Moderators
New to PHP
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
---------------------------------------------------------------------------
<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
read this
viewtopic.php?t=511
and your questions will be answered.
basically you need to do this
Mark
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
- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
try this
form.php <---No need for this to be a php file, it can be plain html.
heres processform.php
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>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>- dull1554
- Forum Regular
- Posts: 680
- Joined: Sat Nov 22, 2003 11:26 am
- Location: 42:21:35.359N, 76:02:20.688W
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>-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
- johnperkins21
- Forum Contributor
- Posts: 140
- Joined: Mon Oct 27, 2003 4:57 pm
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
Here is the php:
It's just something I threw together as a test. I would much prefer to write proper code than just trash that works.
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>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) {
$commission_total = ($cost * $commission_percent);
echo "$salesperson has sold a car for \$$cost.";
echo "<p>";
echo "$salesperson's commission is \$$commission_total";
}
commission ($cost, $commission_percent, $salesperson);
?>
</body>
</html>