简体   繁体   中英

How to pass a variable in PHP to another page without using $_POST?

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!

I would use sessions .

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/

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

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'] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM