Solved

Push a button and set a session variable

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP: Best way to scan folders and process files 10 59
AJAX, If No returns don't let the AJAX Call run again 2 32
How Close unsubmited attempts 10 42
Google Dork query 7 60
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

685 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