Jump to content

Recommended Posts

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 :)
[!--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]
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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.