Help needed please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jjl
Forum Newbie
Posts: 13
Joined: Wed May 14, 2008 12:31 am

Help needed please

Post by jjl »

I have a page with two input buttons - Button1 retreives info from a database and shows it on screen. If the data is correct I press button two and it saves more info to another file. This is done using php & POST
like this

Code: Select all

 
<?php
if ($_POST['getdetails']) 
    { GetDetails(); }
 
if ($_POST['approve']) // 
       { DoSomethingElse();  // Using the details I retrieve in POST['getdetails'] hopefully
}
 
ApproveForm();
 
function ApproveForm () {
    global  $username, $email;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"
>
<html>
  <head>
   <body>
    <FORM method="POST" action="<?= $_SERVER['PHP_SELF'] ?>">
      <input type="text" name="username" value="<?= $username ?>" SIZE=25 MAXLENGTH=50 />
      <input type="submit" value="Get User Details" name = "getdetails" />
      <input type="submit" value="Approve New User" name = "approve"/>
      <?php 
      echo "Username:  ".$_SESSION[user_name]. "<br />";
      echo "Email:     ".$_SESSION[email]. "<br />";
    </FORM>
  </body>
</html>
<?php
}
?>
 
The trouble I am having is keeping the variable information when the page reloads after pressing Button1.
I need some of the information I retreive from button1 (without having to retreive it again when I press button2.

I get a bit lost with the scope of global variables and am not sure if they are the best way of handling it, maybe cookies will do (but what if they are turned off). If Someone could help me here I would appreciate it. I have made it work Ok, but only by getting the details twice and I was hoping to avoid that. I have a feeling this has something to do with session duration but have not worked it out yet.
Thanks
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Help needed please

Post by panic! »

an ambiguous title such as 'help needed please' will mean less people will read your thread. Try renaming it to something more descriptive. Everyone on here is looking for help so 'help needed please' is redundant.
Post Reply