Jump to content

Simple


vexhawk

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.