Forum Moderators: coopster

Message Too Old, No Replies

very simple form problem

         

shumboom

9:01 am on Apr 13, 2008 (gmt 0)

10+ Year Member



Hi

Im learning php and I just cant get forms to work. Im using easyphp.

My html code is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>9.2 simple form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

<form action "listing9.3.php">
<input type ="text" name="user">

<br>
<textarea name="address" rows="5" cols="40">
</textarea>
<br>
<input type="submit" value="hit it">

</form>

</body>
</html>

and my php file is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>read form 9.2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php

print "Welcome <b> $user</b><P>\n\n";
print "Your address is <P>\n\n<b>$address</b>;
?>

</body>
</html>

and when I post 'John' from 'London' all I see is

http://example.com/Listing9.2.html?user=john&address=london

in the address and the original form on the page. This happens whatever php file I have entered as the action script so is there something wrong with my setup?

many thanks,Shumit

[edited by: dreamcatcher at 1:57 pm (utc) on April 13, 2008]
[edit reason] Use example.com, thanks. [/edit]

wheelie34

9:15 am on Apr 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



welcome to webmasterworld Shumit

Try to POST your form

<form method="POST" action="listing9.3.php">

Then on your listing9.3.php page

Accept the variables

<?php
$user = $_POST['user'];
$address = $_POST['address'];
print "Welcome <b> $user</b><P>\n\n";
print "Your address is <P>\n\n<b>$address</b>;
?>

See if that works

shumboom

10:09 am on Apr 13, 2008 (gmt 0)

10+ Year Member



Hi

Thanks.

Tried that - now the form gets cleared when submitted and I remain on the same page - the url address now remains the same. Again putting in a non-existent php file makes no difference. Its driving me mad!

S

tutorial

10:28 am on Apr 13, 2008 (gmt 0)

10+ Year Member



I don't see anything that could cause this problem. Did you name your php file correctly?

wheelie34

3:34 pm on Apr 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I noticed in your initial post you were calling it via local host 127.0... (which has been edited to use example.com) I also noticed you called it via .html and with a capital L

Listing9.2.html?user=john&address=london

You can, via htaccess, call php within an html document, but I somehow doubt you are doing that, so, are you sure everything is correct? are you sure the equals sign ( = ) is before listing.9.2 in the action

action="list...

try this at the top of listing9.2.php

print_r ($_POST);

See what it returns, it's an easy way to spot if your variables are actually arriving.

Also try and add the missing " on this line

print "Your address is <P>\n\n<b>$address</b>HERE;<---

shumboom

10:27 am on Apr 14, 2008 (gmt 0)

10+ Year Member



Hi

you got it! It was the missing '=' before the action ! v sorry but I guess its all part of the learning process.

thanks,Shumit