Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 30th, 2004, 06:57 AM
Registered User
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to tell which button clicked


In my webpage I query a mysql database for records and display them on the page using php, in a loop. Next to each item I put a button for the user to interact with that particular item; currently I give the button's 'name' attribute the value of the item's primary key.

The problem is that I can't figure out how to tell, on the form-processing page, which of these buttons was pressed by the user to get there, since the names are generated at run-time so I can't just test for each one in advance. I've tried setting a session variable in the 'onClick' attribute of the button but it doesn't seem to work.

Any suggestions?

Old November 30th, 2004, 08:53 AM
Friend of Wrox
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul

if ini_set() can handle 'session.use_trans_sid' variable, use it else a hidden form field can transit $_POST or $_GET values to action page.

Old November 30th, 2004, 01:35 PM
Registered User
Join Date: Nov 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for your response.

I don't entirely understand your first suggestion; I tried googling it and then tried setting it to 'true', but this didn't seem to change anything.

I don't understand either how a hidden form field would help, since how would I know what it was called in order to see what value it had? The problem is that I don't know in advance the number of items that will be displayed, and therefore their primary keys/names.

Ideally I would like to be able to say 'give me the name of the button that was clicked' since that would tell me the primary key, but I can't say 'was it button x, was it button y' etc. since I don't know x, y, z in advance.

The only thing I can think of is that the primary keys are auto-increment integers, i.e. 1, 2, 3, 4...etc so I could keep checking if $form_1, $form_2, $form_3 etc. were set until I found it, but presumably it's not possible to dynamically change a variable $form_x to those values incrementally at run-time?

Thanks again, and sorry if/that I've missed the point completely.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form does not open when commandbar button clicked Arsi BOOK: Professional Outlook 2007 Programming ISBN: 978-0-470-04994-5 21 March 5th, 2009 04:03 AM
How to know whick button was clicked. KingArthur Struts 1 February 22nd, 2006 07:12 AM
Determining Which Button Was Clicked BrianWren ASP.NET 1.0 and 1.1 Basics 3 May 5th, 2005 03:24 PM
links to a page when a button is clicked hosefo81 HTML Code Clinic 4 December 7th, 2003 06:47 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.