2

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

1
  • you should check it first with if(isset($_GET['q'])) before echoing it to not run in php notices.
    – 32bitfloat
    Jul 12, 2012 at 13:41

2 Answers 2

8

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"/>
1
  • please complete your answer with value="<?php echo isset($_GET['q']) ? $_GET['q'] : NULL; ?>" I think with this solve all future problem with any servers.
    – Sena
    Jul 12, 2012 at 13:45
5

You forgot to call echo. Your code should read:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.