943,553 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1620
  • PHP RSS
Apr 8th, 2007
0

Help with form buttons

Expand Post »
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.

PHP Syntax (Toggle Plain Text)
  1. //form page
  2. <table>
  3. <tr><td>
  4. <form action="process.php" method="POST">
  5. Update att1: <input type="hidden" name="subupgradestat" value="att1">
  6. <input type="submit" name="att1" value="att1">
  7. </form>
  8. </td></tr>
  9. </table>

PHP Syntax (Toggle Plain Text)
  1. //process.php
  2. function procUpdateStat()
  3. {
  4. global $session, $database;
  5.  
  6. if($_POST['att1'])
  7. {
  8. $database->addOneStat($field);
  9. header("Location: index.php?page=levelup&id=$session->userid");
  10. }
  11. }
Reputation Points: 10
Solved Threads: 3
Junior Poster
Barefootsanders is offline Offline
165 posts
since Oct 2006
Apr 13th, 2007
0

Re: Help with form buttons

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.
Reputation Points: 15
Solved Threads: 17
Junior Poster
phper is offline Offline
189 posts
since Nov 2006
Apr 14th, 2007
0

Re: Help with form buttons

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

and in your php do:

if($_POST['submit'] == "att1") {
do stuff...
}
Reputation Points: 17
Solved Threads: 14
Posting Whiz
DanceInstructor is offline Offline
355 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: mysql injection
Next Thread in PHP Forum Timeline: new to PHP and need help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC