Jump to content


Photo

Simple


  • Please log in to reply
5 replies to this topic

#1 vexhawk

vexhawk
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 September 2006 - 10:46 PM

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>


#2 sford999

sford999
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 24 September 2006 - 10:59 PM

Firstly the form is wrong

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

Then in page2.php you would need
<?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 form
echo "You typed ".$id;

?>


#3 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 24 September 2006 - 11:04 PM

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.

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


#4 vexhawk

vexhawk
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 September 2006 - 11:05 PM

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.

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 24 September 2006 - 11:06 PM

i would do it that way too...but the book claims this method works.


The book is outdated.

#6 vexhawk

vexhawk
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 24 September 2006 - 11:09 PM

i should get a new book, thats for ur e-mail.  you method makes a lot more sense.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users