brucebat
brucebat

Reputation: 41

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:

Any ideas how this can be implemented?

Thanks

Preferably not in a session if possible!

Upvotes: 1

Views: 2710

Answers (5)

Chrobot
Chrobot

Reputation: 11

Try using a session.

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

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

Upvotes: 1

Shameer
Shameer

Reputation: 3066

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/

Upvotes: 2

Jack Franklin
Jack Franklin

Reputation: 3765

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".

Upvotes: 1

Drazisil
Drazisil

Reputation: 3343

I would use sessions.

Upvotes: 3

Tudor Constantin
Tudor Constantin

Reputation: 26861

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

Upvotes: 1

Related Questions