User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,182 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,794 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 937 | Replies: 2
Reply
Join Date: Oct 2006
Posts: 128
Reputation: Barefootsanders is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
Barefootsanders Barefootsanders is offline Offline
Junior Poster

Help with form buttons

  #1  
Apr 8th, 2007
Hey everyone. I'm trying to write code to update a stat field within my database and I'm having some trouble passing the variables from the form page to the process page. Below is my code. I know it's not correct. I just want a button to say "Upgrade attribute 1" and on click it goes to process.php, figures out what button was clicked and then runs the function addOneStat which adds one to the stat field. In the future I will have many buttons and I was hoping that the process page could tell the difference between what button was clicked. Any suggestions?? Thanks.

//form page
    <table>
        <tr><td>
        <form action="process.php" method="POST">
            Update att1: <input type="hidden" name="subupgradestat" value="att1">
                         <input type="submit" name="att1" value="att1">
        </form>
        </td></tr>
    </table>

//process.php
    function procUpdateStat()
    {
        global $session, $database;
        
        if($_POST['att1'])
        {
            $database->addOneStat($field);
            header("Location: index.php?page=levelup&id=$session->userid");
        }
    }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation: phper is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 11
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: Help with form buttons

  #2  
Apr 13th, 2007
Instead of using buttons why not use just a hyperlink -

example:
<a href="process.php?att=Attribute1">Upgrade attribute 1</a>
<a href="process.php?att=Attribute2">Upgrade attribute 2</a>

etc. etc. etc. etc.
Reply With Quote  
Join Date: Feb 2005
Posts: 354
Reputation: DanceInstructor is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 12
DanceInstructor's Avatar
DanceInstructor DanceInstructor is offline Offline
Posting Whiz

Re: Help with form buttons

  #3  
Apr 14th, 2007
<input type="submit" value="att1">

and in your php do:

if($_POST['submit'] == "att1") {
do stuff...
}
Clear Mind Hosting and Web Design

If I've helped you please consider adding to my reputation.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC