echoed Posted April 7, 2009 Share Posted April 7, 2009 On my administration page i want to be able to easily update hockey statistics and such ,this is just a small example portion of what the page will be but after i get this to work i should be able to finish the rest. When i click on the + or - i want it to Update the goals and either add or subtract 1 to the entry. My Form <html> <body> <form name="form" method="post" action="process_update_player.php"> Player: <input type="text" name="player"><br /> Goals<input type="submit" name="g_add" value="+"><input type="submit" name="g_subtract" value="-"><br> </form> </body> </html> My php code(process_update_player.php) <?php $player = $_POST['player']; $add = 1; $subtract = 1; $conn=mysql_connect("localhost","****","********"); mysql_select_db("***********"); if(isset($_POST['g_add'])){ $query="UPDATE `mklseason5` SET `season_goals` += `$add` WHERE `player` = `$player`"; mysql_query($query) or die("Cannot add"); echo "succesfully added goal to ". $player; } if(isset($_POST['g_subtract'])){ $query="UPDATE `mklseason5` SET `season_goals` -= `$subtract` WHERE `player` = `$player`"; mysql_query($query) or die("Cannot subtract"); echo "succesfully subtracted goal to ". $player; } ?> Quote Link to comment Share on other sites More sharing options...
Fruct0se Posted April 7, 2009 Share Posted April 7, 2009 This is actually most likely working, however you have both + and - in the same form so when you submit it both + and - will be set. This means that your code will add 1 then immediately subtract 1. Quote Link to comment Share on other sites More sharing options...
echoed Posted April 7, 2009 Author Share Posted April 7, 2009 Well when i click on the + or - the or die("Cannot add"); or or die("Cannot subtract"); is displayed on the page. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 7, 2009 Share Posted April 7, 2009 The SQL query isn't valid try this to add UPDATE `mklseason5` SET `season_goals` = `season_goals`+1 WHERE `player` = `$player` and this to subtract UPDATE `mklseason5` SET `season_goals` = `season_goals`-1 WHERE `player` = `$player` Quote Link to comment Share on other sites More sharing options...
echoed Posted April 8, 2009 Author Share Posted April 8, 2009 Still not working =\. Quote Link to comment Share on other sites More sharing options...
Ashoar Posted April 8, 2009 Share Posted April 8, 2009 Try changing the second IF to an ELSE IF, in your section for updating the table information. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 8, 2009 Share Posted April 8, 2009 That really doesn't give me anything to work with!!! So in reply! It should be! Still not working =\. Quote Link to comment Share on other sites More sharing options...
echoed Posted April 8, 2009 Author Share Posted April 8, 2009 That really doesn't give me anything to work with!!! So in reply! It should be! Still not working =\. <?php $player = $_POST['player']; $conn=mysql_connect("****","**********","********"); mysql_select_db("******"); if(isset($_POST['g_add'])){ $query="UPDATE `mklseason5` SET `season_goals` = `season_goals`+1 WHERE `player` = `$player`"; mysql_query($query) or die("Cannot add"); echo "succesfully added goal from ". $player; } if(isset($_POST['g_subtract'])){ $query="UPDATE `mklseason5` SET `season_goals` = `season_goals`-1 WHERE `player` = `$player`"; mysql_query($query) or die("Cannot subtract"); echo "succesfully subtracted goal from ". $player; } ?> Also tried Ashoar's advice and it doesn't work. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 8, 2009 Share Posted April 8, 2009 it doesn't work. doesn't help much! does it run the query? try changing value="+" and value="-" to value="add" Quote Link to comment Share on other sites More sharing options...
echoed Posted April 8, 2009 Author Share Posted April 8, 2009 it doesn't work. doesn't help much! does it run the query? try changing value="+" and value="-" to value="add" Nope, the query doesn't run. Quote Link to comment Share on other sites More sharing options...
redarrow Posted April 8, 2009 Share Posted April 8, 2009 look at your code man, look at the ``````` on the where clause use ' ' not ` Quote Link to comment Share on other sites More sharing options...
echoed Posted April 9, 2009 Author Share Posted April 9, 2009 Can't believe i missed that ...-.- Thanks a million. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.