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");
        }
    }

Recommended Answers

All 2 Replies

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.

<input type="submit" value="att1">

and in your php do:

if($_POST == "att1") {
do stuff...
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.