Solved

Push a button and set a session variable

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now