Jump to content

Quick form question


fantombe

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
Link to comment
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
Link to comment
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
Link to comment
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?
Link to comment
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.
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.