I want to pass a variable to another page by form data. I've looked at other tutorials and codes, i've followed them closely, but the contents of the variable doesn't output. Basically php doesn't work inside the value="". Here's the code.
page 1.
<?php
$hi = 1224;
?>
<form method = "post" action = "page2.php">
<input type = "hidden" Name = "var" Value = "<?phpecho$hi;?>"/>
<input type = "submit" Name = "enter" Value = "Submit"/>
</form>
page 2.
<?php
$test = $_REQUEST['var'];
echo $test;
?>
Nothing is outputted. I've even tried session variables but somehow they worked but once i refreshed the page, the variables were reset. I've started sessions on all pages etc..
When something isn't working, make sure to check the source code for error, don't just look browser's rendering. In the source, you'd clearly have seen that <?phpecho$hi;?>
wasn't evaluated, but instead just printed in the source.
So in conclusion, <?phpecho$hi;?>
is wrong. Write <?php echo $hi;?>
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments