这怎么办? [关闭]

I know this code doesn't work. I want to pass $var1, $var2, and name to next.php. How can I do that?

<?php
    $var1="test1";
    $var2="test2";
?>

<form method="get">
    <input type="text" name="name">
    <a <?php echo "href='next.php?test1=".$var1."&test2=".$var2."'"?> >next</a>
</form>

in next.php

$var1=$_GET['name'];
$var2=$_GET['test1'];
$var3=$_GET['test2'];

You can pass the values as hidden inputs so that your other values in the form would still be passed with it.

<form action="next.php">
    <input type="text" name="name">
    <input type="hidden" name="test1" value="<?php echo $var1; ?>">
    <input type="hidden" name="test2" value="<?php echo $var2; ?>">
    <button type="submit">Submit</button>
</form>

Then in your next.php, you will receive everything in the $_GET.

Example, if the user fills in Foo as the name and click on submit, then you will receive the following in your next.php:

var_dump($_GET)

array(3) {
    ["name"]=> string(3) "Foo"
    ["test1"]=> string(5) "test1"
    ["test2"]=> string(5) "test2"
}

Change it to :

<form method='GET' action='next.php'>
   <input type='text' name='name' />
   <input type='hidden' name='test1' value="<?php echo $var1;?>" />
   <input type='hidden' name='test2' value="<?php echo $var2;?>" />
</form>