Click to See Complete Forum and Search --> : php sytax


ev66
05-15-2005, 03:40 AM
This may be a html prop,but think its php.
I'm trying to pass the value of a variable using the Form, Post method
but all i keep getting is the variable name and not its value.I know its something simple,but i,ve tried all variations of ' and " but cant get it to work.heres my code

page1
<body><?php
$mycol="red";
$dis='<form name="form1" method="post" action="login2.php">
<input name="hiddenField" type="hidden" value="$red">
<input type="submit" name="Submit" value="Submit">
</form>';
echo '<p>' . $dis . '<p>';
?>
</body>


page2
<body>
<?php
$mycol=$_POST['hiddenField'];
echo $mycol;
?>

this just echos $red and not red as i want it.
Thanks for your help
evan

Scleppel
05-15-2005, 08:20 AM
EDIT: the post below is better.


PAGE ONE

<body>
<?php
$mycol = 'red';
$dis = '<form name="form1" method="post" action="login2.php">'.
'<input name="hiddenField" type="hidden" value="'.$mycol.'">'.
'<input type="submit" name="Submit" value="Submit">'.
'</form>';
echo '<p>' . $dis . '<p>';
?>
</body>

shimon
05-15-2005, 08:22 AM
Ok, well firstly you haven't set a variable called '$red' anywhere, and secondly, enclosing a string in single quotes means that any variables within it won't be expanded.

There's no real reason to construct your HTML as a PHP string variable anyway, it's much nicer to try to seperate the two 'languages'.

Isn't this a lot cleaner? :)

Page 1:

<?php
$mycol = 'red';
?>
<body>
<form method="post" action="login2.php">
<input name="hiddenField" type="hidden" value="<?php echo $mycol; ?>" />
<input type="submit" name="Submit" value="Submit" />
</form>
</body>


Page 2

<?php
echo $_POST['hiddenField'];
?>

ev66
05-15-2005, 10:27 AM
Thanks Scleppel and shimon.lot clearer now.