Jump to content

Archived

This topic is now archived and is closed to further replies.

vexhawk

Simple

Recommended Posts

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>

Share this post


Link to post
Share on other sites
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 form
echo "You typed ".$id;

?>[/code]

Share this post


Link to post
Share on other sites
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]

Share this post


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

Share this post


Link to post
Share on other sites
[quote]i would do it that way too...but the book claims this method works.[/quote]

The book is outdated.

Share this post


Link to post
Share on other sites

×

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.