sonia
sonia

Reputation: 1

I want to pass variale from URL to the input text filed

Hi I have a URL http://example.com/sr_web/confirm_place/index.php?student=123456&surname=test&firstname=Bugsy, I want the student, surname and forename to get displayed into my input text boxes by doing <?php echo $_GET['surname']; ?>

But value is not getting displayed. It is getting displayed if I remove the input box and only echo itself <?php echo $_GET["student"]; ?> within the <td>. But when I write the following:

<input type="text" name="student" id="student" value="<?php echo $_GET["student"]; ?>"> 

input box get displayed blank.

It is getting passed (I checked the source) but does not get displayed in the input box, can anyone help?

Upvotes: 0

Views: 217

Answers (3)

Sam Parmenter
Sam Parmenter

Reputation: 1841

The only thing I can imagine that would cause this would be an incorrect use of GET. Are you sure that you are using GET and not POST. Is the url displaying myurl.html?firstname=john&surname=smith

Upvotes: 0

Leif
Leif

Reputation: 2160

Checking the source alone, you could have overlooked something. Do a

var_dump($_GET['surname']);

If the surname is not appearing somewhere on the screen, something is wrong.

Try to write something like this:

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

but not within php tags.

Upvotes: 0

Michael Irigoyen
Michael Irigoyen

Reputation: 22947

You need to put the value of the $_GET variable in the value attribute. You also want to run htmlentities when doing this.

<input type="text" name="surname" value="<?php htmlentities($_GET['surname']); ?>" />

Upvotes: 2

Related Questions