Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Push a button and set a session variable

Posted on 2009-07-14
3
732 Views
Last Modified: 2013-12-13
Yeah, so I'd like to navigate from one PHP page to another using a button. When the button is clicked I need to store some id value in the $_SESSION array to be used by the page I'm calling. How do I do this?

Below is the code for the button calling the php. I can pass the variable using GET but instead I'd like to use $_SESSION.

Thanks in advance!

      
print "<td align=\"center\"><input type=\"button\" name=\"modify_button\" value=\"Modify\" id=\"a-button\" ONCLICK=\"window.location.href='modify-ad.php\"></td>\n";

Open in new window

0
Comment
Question by:php-newbie
  • 2
3 Comments
 
LVL 4

Expert Comment

by:khyer123
ID: 24855362
here it is in php




<?php
session_start();
$_SESSION['name'] = <value>;
?>
 
<form action="destination_page.php" method="post">
<input type="submit" value="whatyouwantbuttontosay" />
</form>

Open in new window

0
 
LVL 4

Accepted Solution

by:
khyer123 earned 250 total points
ID: 24855373
Here's another solution... if you are trying to get some sort of value that a user enters in and carry it across, and you don't want to use get... then just do the below. On the next page, you can access the value via $_POST['id'], and it won't show up in the URL like get does.
<form action="destination_page.php" method="post">
<input type="text" name="id" />
<input type="submit" value="whatyouwantbuttontosay" />
</form>

Open in new window

0
 

Author Closing Comment

by:php-newbie
ID: 31603545
works for me :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question