View Single Post
Join Date: Nov 2007
Posts: 3,760
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 332
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: Using php and html forms to update a mysql database

 
0
  #2
Dec 19th, 2007
  1. <html>
  2. <body>
  3. <form name="form" method="post" action="test.php">
  4. Number: <input type="text" name="number"><br />
  5. <input type="submit" name="add" value="+"><input type="submit" name="subtract" value="-">
  6. </form>
  7. </body>
  8. </html>
  9. <?php
  10. $conn=mysql_connect("localhost","username","password");
  11. mysql_select_db("dbname");
  12. if(isset($_POST['add'])){
  13. $add=$_POST['number'];
  14. $query="update goods set stock=stock+$add where id=1";
  15. mysql_query($query) or die("Cannot update");
  16. }
  17. if(isset($_POST['subtract'])){
  18. $subtract=$_POST['number'];
  19. $query="update goods set stock=stock-$subtract where id=1";
  20. mysql_query($query) or die("Cannot subtract");
  21. }
  22. ?>

Umm.. you forgot to put your code in [ c o d e ] [ / c o d e ] tags. Anyways, I hope this helps.
Last edited by nav33n; Dec 19th, 2007 at 8:15 am.
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote