ECHO $_GET INTO INPUT FIELD

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

nevodj
New php-forum User
New php-forum User
Posts: 11
Joined: Thu Jun 21, 2012 3:43 pm

ECHO $_GET INTO INPUT FIELD

Postby nevodj » Thu Oct 04, 2012 1:37 am

Hello,

Can someone tell me what is wrong with this code? THE WID input box just shows <?php echo $_GET["sessionid"]; ?>

Code: Select all

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$id = $_GET["sessionid"];
?>
<form id="Registration" name="Registration" method="post" action="collect.php">
  <p>
    <label for="WID">WID</label>
    <input name="WID" type="text" id="WID" value="<?php echo $_GET["sessionid"]; ?>" />
  </p>
  <p>
    <label for="FirstName">First Name</label>
    <input type="text" name="FirstName" id="FirstName" />
  </p>
  <p>
    <label for="LastName">Last Name</label>
    <input type="text" name="LastName" id="LastName" />
  </p>
  <p>
    <label for="Email">Email</label>
    <input type="text" name="Email" id="Email" />
  </p>
  <p>
    <input type="submit" name="Register" id="Register" value="Register" />
  </p>
</form>
</body>
</html>

kyle04
New php-forum User
New php-forum User
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm

Re: ECHO $_GET INTO INPUT FIELD

Postby kyle04 » Thu Oct 04, 2012 2:24 am

Code: Select all

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


This will only work if the sessionid variable has been passed via a url parameter.
To get the current php session id :

$sessionid = session_id();

User avatar
jotorres1
New php-forum User
New php-forum User
Posts: 35
Joined: Thu Oct 27, 2011 1:24 pm
Contact:

Re: ECHO $_GET INTO INPUT FIELD

Postby jotorres1 » Thu Oct 04, 2012 6:31 am

Is this even a ".php" file? Are you running it locally with an apache installed? Also, just like kyle04 said, if you are trying to get the actual session id, first thing you have to do is start the session. You do this at the beginning of the file:

Code: Select all

<?php session_start();
     // etc..
?>

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: ECHO $_GET INTO INPUT FIELD

Postby seandisanti » Thu Oct 04, 2012 12:54 pm

It works on my side. make sure when you're testing it, you're going to

localhost/whatever/scriptname.php?sessionid=x

where the variables are populated to match your environment and session id.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests