如何在不使用$ _POST的情况下将PHP中的变量传递给另一个页面?

How does one pass a PHP variable stored on one page that is NOT in a form, go to another page where a function uses it?

The reason I need this is so a user can adjust their form they are using by adding more rows with a submit button.

This is what I want to achieve:

  • $maxrows = stores the total amount of rows currently on the page

  • user presses "add more rows button"

  • another page is loaded which has a function which adds $maxrows + 5

  • once complete, the page redirects to the form

  • the form redisplays the page with 5 more rows

Any ideas how this can be implemented?

Thanks

Preferably not in a session if possible!

Use it with GET parameters - include the variable in the URL that loads your new page like

http://example.com/file.php?maxrows=10

In file.php you get it by using $_GET instead of $_POST

I would use sessions.

You could use $_GET instead of $_POST.

You pass the variable in to the page via the url:

someurl.com/page.php?somevar=hello

Then in page.php you can use $_GET['somevar'] which will equal "hello".

Try using a session.

Put start_session(); at the beginning of your script.

You can store the number of rows in $_SESSION['max_rows'].

you can use jQuery + ajax to achieve this. Here when you click on add more rows it will add up just dome elements with dynamic names. The concept can be understood from http://charlie.griefer.com/blog/2009/09/17/jquery-dynamically-adding-form-elements/