master82 Posted March 7, 2006 Share Posted March 7, 2006 OK, below is my current code. It takes a value from a submitted form and adds this value to my 'users' table in the 'salestodate' field.I was hoping that it would also add this number to the current number stored on the database, but it replaces it (with the submitted number) rather than replace it withthe sum of the two (submitted and that already on the database).Anyone know what I can tweek to make this happen?[code]<?php$conn = mysql_connect("localhost", "username", "password");mysql_select_db("database",$conn);$sql = mysql_query("SELECT * FROM Users");$finalnumber = intval($_POST['sales']) * (0.75);$finalnum = ($finalnumber + intval($row['salestodate']));$sql = mysql_query("UPDATE Users SET salestodate = '$finalnum'");if($sql) { echo "Success!";} else { echo "Failed...";}?>[/code]Thanks in advance to the genious who has the solution :) Quote Link to comment Share on other sites More sharing options...
dcro2 Posted March 7, 2006 Share Posted March 7, 2006 [!--quoteo(post=352665:date=Mar 7 2006, 06:04 PM:name=master82)--][div class=\'quotetop\']QUOTE(master82 @ Mar 7 2006, 06:04 PM) [snapback]352665[/snapback][/div][div class=\'quotemain\'][!--quotec--]$sql = mysql_query("SELECT * FROM Users");$finalnumber = intval($_POST['sales']) * (0.75);$finalnum = ($finalnumber + intval($row['salestodate']));[/quote]In this line:$finalnum = ($finalnumber + intval($row['salestodate']));you haven't fetched the results from:$sql = mysql_query("SELECT * FROM Users");You need to use:[code]$sql = mysql_query("SELECT * FROM Users");$row = mysql_fetch_assoc($sql);$finalnumber = intval($_POST['sales']) * (0.75);$finalnum = ($finalnumber + intval($row['salestodate']));[/code] Quote Link to comment Share on other sites More sharing options...
master82 Posted March 8, 2006 Author Share Posted March 8, 2006 Cheers for the reply,I've added the line that you suggested but still no luck, its still only populating the field with the submitted number and not a combination of the two.Is there any other approach I could use?[!--quoteo(post=352678:date=Mar 7 2006, 11:50 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Mar 7 2006, 11:50 PM) [snapback]352678[/snapback][/div][div class=\'quotemain\'][!--quotec--]In this line:$finalnum = ($finalnumber + intval($row['salestodate']));you haven't fetched the results from:$sql = mysql_query("SELECT * FROM Users");You need to use:[code]$sql = mysql_query("SELECT * FROM Users");$row = mysql_fetch_assoc($sql);$finalnumber = intval($_POST['sales']) * (0.75);$finalnum = ($finalnumber + intval($row['salestodate']));[/code][/quote] 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.