Jump to content


Photo

Quick form question


  • Please log in to reply
8 replies to this topic

#1 fantombe

fantombe
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 August 2006 - 12:19 PM

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...s/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

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 12:22 PM

thats becasue now in PHP you need to use $_POST

so

<?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"; 
?>

becomes

<?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"; 
?>


Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 fantombe

fantombe
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 August 2006 - 12:31 PM

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

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 12:35 PM

just paste all your coding here mate i'm sure we can find the issue :)
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 fantombe

fantombe
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 August 2006 - 12:42 PM

I appreciate the help. This is Dreamweavers bastardised version of the html:

<!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>

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

#6 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 12:51 PM

can you paste what you have in process.php also because i tested you code here www.ukchat.ws/phpfreaks/testpost.php and it works fine with the process.php code i pasted above..
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#7 fantombe

fantombe
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 August 2006 - 12:54 PM

It's this now:

<?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"; 
?>

What you posted for me above.

#8 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 01:48 PM

Hmm that's very weird because i tested the idectical code and it works.. try this..

create a new file test.php

<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");
}
?>

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

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#9 fantombe

fantombe
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 11 August 2006 - 04:59 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users