fantombe Posted August 11, 2006 Share Posted August 11, 2006 Hi AllI'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.htmBut 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 Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 11, 2006 Share Posted August 11, 2006 thats becasue now in PHP you need to use $_POSTso [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]RegardsLiam Quote Link to comment Share on other sites More sharing options...
fantombe Posted August 11, 2006 Author Share Posted August 11, 2006 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. ;DAnthony Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 11, 2006 Share Posted August 11, 2006 just paste all your coding here mate i'm sure we can find the issue :) Quote Link to comment Share on other sites More sharing options...
fantombe Posted August 11, 2006 Author Share Posted August 11, 2006 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? Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 11, 2006 Share Posted August 11, 2006 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.. Quote Link to comment Share on other sites More sharing options...
fantombe Posted August 11, 2006 Author Share Posted August 11, 2006 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. Quote Link to comment Share on other sites More sharing options...
shocker-z Posted August 11, 2006 Share Posted August 11, 2006 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><?phpif (isset($_POST['name'])) {$name=$_POST['name'];echo("Your name is $name");}?>[/code]and then see if that echo's your name when you press submitRegardsLiam Quote Link to comment Share on other sites More sharing options...
fantombe Posted August 11, 2006 Author Share Posted August 11, 2006 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. ;DCheers LiamAnthony Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.