Jump to content

Archived

This topic is now archived and is closed to further replies.

fantombe

Quick form question

Recommended Posts

Hi All

I'm having trouble getting a form to work. It's a dead simple form, just a few variables which get posted to the script.

Problem is, the script isn't receiving the data.

To test it, I even tried using this nice simple script here: http://php.about.com/od/learnphp/ss/php_forms.htm

But the script runs fine, prints out the text as expected but leaves blanks where the posted form fields should be?

Can anyone help?

I'm actually about to tear my hair out! ???

Anthony

Share this post


Link to post
Share on other sites
thats becasue now in PHP you need to use $_POST

so

[code]<?php
print "Your name is ". $Name;
print "<br />";
print "You are ". $Age . " years old";
print "<br />";
$old = 25 + $Age;
print "In 25 years you will be " . $old . " years old";
?> [/code]

becomes

[code]<?php
print "Your name is ". $_POST['Name'];
print "<br />";
print "You are ". $_POST['Age'] . " years old";
print "<br />";
$old = 25 + $_POST['Age'];
print "In 25 years you will be " . $old . " years old";
?> [/code]


Regards
Liam

Share this post


Link to post
Share on other sites
Thanks Liam, you're a saint.

Still didn't work, but I made the form in Dreamweaver 8 (recently upgraded) rather than copying and pasting, and when it still didn't work after someone that knows what their doing told me what's wrong, it lead me onto doing the form in notepad. This actualy worked!

So although I still don't know what's stopping it, I now can safetly assume it's something Dreamweaver is putting in the code so can actually start looking for a solution rather than tearing my hair out.

Cheers again, that was really helpful. ;D

Anthony

Share this post


Link to post
Share on other sites
just paste all your coding here mate i'm sure we can find the issue :)

Share this post


Link to post
Share on other sites
I appreciate the help. This is Dreamweavers bastardised version of the html:

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="process.php">
  Name:
  <label>
  <input name="Name" type="text" id="Name" />
  </label>
  <p>Age:
    <label>
    <input name="Age" type="text" id="Age" />
    </label>
  </p>
  <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>[/code]

There's alot of surplus crap in there, anything in particular stand out though so I can keep aneye out in future?

Share this post


Link to post
Share on other sites
can you paste what you have in process.php also because i tested you code here [url=http://www.ukchat.ws/phpfreaks/testpost.php]www.ukchat.ws/phpfreaks/testpost.php[/url] and it works fine with the process.php code i pasted above..

Share this post


Link to post
Share on other sites
It's this now:

[code]<?php
print "Your name is ". $_POST['Name'];
print "<br />";
print "You are ". $_POST['Age'] . " years old";
print "<br />";
$old = 25 + $_POST['Age'];
print "In 25 years you will be " . $old . " years old";
?> [/code]

What you posted for me above.

Share this post


Link to post
Share on other sites
Hmm that's very weird because i tested the idectical code and it works.. try this..

create a new file test.php

[code]<form method="post" action="">
  Name: <input name="name" type="text" id="Name" /><Br />
<input type="submit" name="submit" value="Submit">
</form>
<?php
if (isset($_POST['name'])) {
$name=$_POST['name'];
echo("Your name is $name");
}
?>[/code]

and then see if that echo's your name when you press submit

Regards
Liam

Share this post


Link to post
Share on other sites
That works fine. I even put those label tags back in (whatever they're for!) and it still worked, so it's not them.

So I've gone through the code in the original page and got rid of alot of the surplus crap, and it works now, so that seems to be the answer! Don't ask me to pinpoint exactly what was wrong, but right now I'm going to take the approach of not looking a gift horse in the mouth!

Thanks alot for helping out a novice here. I'm learning as I go along so it's much appreciated. ;D

Cheers Liam

Anthony

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.