shanahobo86
shanahobo86

Reputation: 497

html php retain form value

As the title says, i'm trying to retain the value submitted from a text form. so I thought the following simple code on the pre-process page would do the trick but the text box is still blank.

<form id="form1" name="form1" method="get" action="pre_process.php">
        <input name="q" type="text" value="<?php $_GET['q']; ?>" size="80"/>

Any suggestions?

Thanks

Upvotes: 2

Views: 1714

Answers (2)

andrewsi
andrewsi

Reputation: 10732

Try:

<input name="q" type="text" value="<?php echo $_GET['q']; ?>" size="80"/>

You need to echo the value out.

To avoid Notices you should use the isset function to check if the value was set

Your code should look like:

<input name="q" type="text" value="<?php echo isset($_GET['q']) ? $_GET['q'] : NULL; ?>" size="80"/>

Upvotes: 8

Rawkode
Rawkode

Reputation: 22562

You forgot to call echo. Your code should read:

<?php echo $_GET['q']; ?>

Upvotes: 5

Related Questions