Forum Moderators: coopster

Message Too Old, No Replies

posting variables in hidden field

         

mschultem

10:02 am on Feb 27, 2007 (gmt 0)

10+ Year Member



hi,
i am trying to get the following script working.

it first gets the variables pid and version either from a POST or GET.
these variables should be sent to the next page using the hidden
input fields - the problem is that there is nothing coming out at the other end (test_postget.php)

thanks for suggestions
m


<? require "includes/initialize.inc.php";
// get pid and version info
$pid=$_POST['pid'];
if (!isset($pid)) $pid=$_GET['pid'];
$version=$_POST['version'];
if (!isset($version)) $version=$_GET['version'];
// /////////////////////////////////////////////
if (isset($_POST['confidence'])) {
$sql = "replace into ProFra_Conf set timestart=now(), version=".$version.", position='1',pid=".$pid;
$db->query($sql);
$sql = "update ProFra_Conf set pid=pid";
foreach ($_POST as $key => $value) {
$sql .= ", $key=\"$value\"";
}
$sql .= " where pid=".$pid;
$db->query($sql) or die("error in $sql : ".$db->error);
header("Location: http://example.com/test/test_postget.php");

exit;
}

include $CFG["doc_root"]."/includes/header.inc.php";?>

<b>Confidence</b><br/><br/>
Please answer the following items by clicking on the black bars to indicate how much each statement applies to you.
<br/><br/>
<form name='mainform' method=post onSubmit='return checkform(this,1);'>
<input type=hidden name="pid" value="<?echo($pid)?>">
<input type=hidden name="version" value="<?echo($version)?>">
1. How confident are you about the decision you just made?<br/><br/>
<? continuous_scale("confidence","very confident","not at all confident");?><br/><br/>

<br/>

<table width=100%><tr><td align=right width=100%>

<input type=submit value='Continue' />
</td></tr></table>
</form>
<? include $CFG["doc_root"]."/includes/footer.inc.php";?>

[edited by: dreamcatcher at 10:57 am (utc) on Feb. 27, 2007]
[edit reason] Generalised url. [/edit]

dreamcatcher

10:59 am on Feb 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi mschultem, welcome to Webmaster World. :)

Its because you are using the header function which clears all your variables. Try assigning your vars to session variables and then accessing them on your page.

dc

mschultem

11:23 am on Feb 27, 2007 (gmt 0)

10+ Year Member



hi dreamcatcher (nice name by the way),
thanks for your reply.

a short follow up:
what i do is assigning $pid and $version to session on the page i posted - and getting it from the _SESSION back on the test_getpost.php page ...
right?

which brings also the question into the game how to assign a variable to as session ...

thanks again
mschultem

dreamcatcher

11:43 am on Feb 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you initiating the session on all your pages?

session_start();

Must be at the top of all your pages where you are accessing vars from the session. Then use:

$_SESSION['pid'] = $pid;
$_SESSION['version'] = $version;

On your 'test_getpost.php' page use:

echo $_SESSION['pid'];
echo $_SESSION['version'];

Some people tend to forget to start the session. Also, set your error reporting level to E_ALL for development. That can sometimes filter out any problems.

dc

mschultem

1:29 pm on Feb 27, 2007 (gmt 0)

10+ Year Member



i probably will repeat this from time to time:
you saved my day!
thanks!
mschultem