jeni
jeni

Reputation: 440

Best way to Pass value from one page to another php

Normally i use id to take database values from one page to another. like a example format provided

 location.href='edit_form.php?id=<?php echo $id?>
  1. Is this way be problematic?

  2. Is this ok or can i adopt any other way to pass values from one page to another.

  3. which is the best way to achieve this.

Upvotes: 2

Views: 1448

Answers (1)

ojrac
ojrac

Reputation: 13421

Passing IDs around is simple and it gets the job done. You should expect people to try changing the id to see what happens, but as long as you don't show users pages they shouldn't be able to hit, it sounds great.

While I think the query string is right for what you're doing, there are more options:

  • POSTing a form (requires JavaScript, extra work to add hidden form fields, and it's usually a worse experience for the user if they refresh or use the history)
  • Using sessions, which gets very messed up if your user has multiple tabs open, adds extra stress on your servers, and if the user takes a long time between clicks (esp. if they leave a browser open for a few hours and come back), the links will stop working because the session expires
  • Using cookies, which also gets messed up if your user has multiple tabs open, but (unlike sessions) doesn't stress your server or expire if you don't want them to

Upvotes: 2

Related Questions