Page 1 of 1

ECHO $_GET INTO INPUT FIELD

Posted: Thu Oct 04, 2012 1:37 am
by nevodj
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>

Re: ECHO $_GET INTO INPUT FIELD

Posted: Thu Oct 04, 2012 2:24 am
by kyle04

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();

Re: ECHO $_GET INTO INPUT FIELD

Posted: Thu Oct 04, 2012 6:31 am
by jotorres1
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..
?>

Re: ECHO $_GET INTO INPUT FIELD

Posted: Thu Oct 04, 2012 12:54 pm
by seandisanti
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.