Jump to content

[SOLVED] Increment field by input value


lucy

Recommended Posts

How can i create a form, which when an integer is inputted, it ads the value of this, to the previous records same value?

 

For example, if i was to create a database to record number of goals in the season (lame i know!). after each game i would enter how many goals i had scored that day, and adding them to the total number of goals for the season?

 

Thanks,

Lucy

Link to comment
Share on other sites

I thought it was solved but its not.

 

I know how to increment the total number of goals scored but it changes the value for the previous total number of goals scored after each game to the current total number of goals. I need the database to show the total number of goals for the game were adding and all previous ones e.g.:

 

game 0      goals scored=0        total number=0

game 1      goals scored= 3        total number = 3

game 2      goals scored=1        total number = 4

game 3      goals scored =0        total number = 4

e.t.c.

 

but what im getting is the total number of goals in all records is set to the current toal e.g.

 

game 0    goals scored = 0    total number = 4

game 1    goals scored = 3    total number = 4

game 2    goals scored = 1    total number = 4

game 3    goals scored = 0    total number = 0

 

How can i make it so the total number of goals, for each record, is the sum of the goals scored for this record + the total number of goals for the previous record?

 

the code i have at the moment:

$user=BLANK
$password=BLANK
$database=BLANK

//connect to the database
$con = mysql_connect("localhost",$user,$password) or die ('Could not connect: ' . mysql_error());

//select the database
mysql_select_db($database, $con);


$goals= $_POST[goals];


mysql_query("INSERT INTO table1 VALUES ('','','','','','','$_POST[goals]','','','')") or die('Error: ' . mysql_error());




mysql_query("UPDATE table1 SET total_goals= total_goals + $goals");

 

Thanks for any help :)

Lucy

Link to comment
Share on other sites

Ive done it now. I had an auto increment field in the table so i did it the following way:

 

$goals= $_POST[goals];

$query= mysql_query("SELECT total_goalsFROM table1 ORDER BY number DESC LIMIT 1");
$goals1 = mysql_fetch_array( $query);
$goals2 = $time1['total_goals'];


$new_total_goals= $goals+ $goals;

 

Thanks,

Lucy

Link to comment
Share on other sites

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.