Solved

Push a button and set a session variable

Posted on 2009-07-14
3
731 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php simple error message 4 25
error log using ftp 7 41
Cpanel file manager 8 25
PHP error function not working on AWS 10 14
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 count occurrences of each item in an array.

831 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