Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Novice Question

Status
Not open for further replies.

gpet

Technical User
May 18, 2007
17
GR
Hi everyone

I have two question to ask
first how can i use two submit buttons and tell php that when i press that button to do one thing and when i press the other
button to do something else?
Second how can i declare a variable that i will be able to see the value in address bar of my explorer so i can use it later
for example
$var = 10;
$_GET['test'] = $var;
How can i see the result in address bar like

Thanks for replying

Sorry if my english are bad
 
second question:
set the method of the form to GET

first question
name each submit button the same thing, set their values differently
e.g.
Code:
<input type="submit" name="submit" value="First Button" />
<input type="submit" name="submit" value="Second Button" />

then in your receiving code do this

Code:
if (isset($_GET['submit'])){

  if ($_GET['submit'] === "First Button") {
  // do something
  } elseif($_GET['submit'] === "Second Button") {
  // do something else
  } else {
  //do something else again
  }
}
if you have more than two buttons it would be easier to use a switch statement rather than if...elseif...else
 
thanks for replying jpadie

About first question i have the form with get method the problem is that i want a variable like current record of a database to get it in the address bar so i can use it for other reason
I don t know if what am i saying makes sense i am trying make it as simple as i can.

 
all fields within the form are transferred in the querystring when the method is set to get.

if you want to have a particular value made "sticky" then you can either.
1. create a hidden field in the form and populate its value argument or
2. [preferred] set the value in a session variable before delivering the form.

sessions are by far the best way of creating persistent data storage. if you are unfamiliar with sessions then do read the manual but, for simplicity's sake the following rules should set you straight

Code:
session_start();// you cannot access any session data (read/write) before calling this function.
$_SESSION['something'] = 'somevalue'; // to set a session element just use like an array
echo $_SESSION['something']; //ditto to retrieve its data
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top