vexhawk Posted September 24, 2006 Share Posted September 24, 2006 Trying to learn php. i want to kno why this doesn't work:(i copied the example from the book but i changed the HTML to XHTML. If i type something, say in the text field, it should be echoed but it doesn't. PLease help.--------------------------------------<html><form>Please type your username here:<br /><input type="text" name="id" /><br /><br /><input type="submit" value="submit data" /></form><br /><br />You typed:<?php echo ($id);?></html> Quote Link to comment Share on other sites More sharing options...
sford999 Posted September 24, 2006 Share Posted September 24, 2006 Firstly the form is wrong[code]<form enctype="multipart/form-data" action="page2.php" method="post">Please type your username here:<input type="text" name="id" /><input type="submit" value="submit data" /></form>[/code]Then in page2.php you would need[code]<?php// Use $id = $_GET['id']; to retreive the form data and put it into a variable$id = $_GET['id'];// echo out what was sent in the formecho "You typed ".$id;?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted September 24, 2006 Share Posted September 24, 2006 There is nothing wrong with your form, but yes, you need to reference variables sent by the GET or POST methods in there corresponding arrays. By default, a form sends via GET unless otherwise specified so your code to echo the result would be.[code]<html><form>Please type your username here:<input type="text" name="id" /><input type="submit" value="submit data" /></form>You typed:<?php if (isset($_GET['id'])) { echo $_GET['id']; }?></html>[/code] Quote Link to comment Share on other sites More sharing options...
vexhawk Posted September 24, 2006 Author Share Posted September 24, 2006 i would do it that way too...but the book claims this method works which made me scratch my head because the php portion didn't make much sense. Quote Link to comment Share on other sites More sharing options...
trq Posted September 24, 2006 Share Posted September 24, 2006 [quote]i would do it that way too...but the book claims this method works.[/quote]The book is outdated. Quote Link to comment Share on other sites More sharing options...
vexhawk Posted September 24, 2006 Author Share Posted September 24, 2006 i should get a new book, thats for ur e-mail. you method makes a lot more sense. 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.