Skip to main content
Inspiring
April 25, 2006
Question

button to add one to database total

  • April 25, 2006
  • 2 replies
  • 363 views
HI Folks,

I'm new to all of this PHP business but I'm working though a project to create a quiz site. It will never see the light of day but I thought it would help me learn.

I have set up a MySQl table with 3 rows - id, teamname and teamscore.

Each team name to appears at the top of the page with the current score underneath. What I would like to add is a button or link below that which when clicked adds one to the teamscore.

Can anyone point me in the right direction?

Cheers

Tubby
This topic has been closed for replies.

2 replies

Inspiring
April 27, 2006
Can anyone out there help me. I've still struggling with this one
Inspiring
April 27, 2006
You had the right idea to use a form,
use the update record wizard, this will generate the update sql required at the top of your page. You will need to modify this code slightly by adding +1 .

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE table_name SET temascore= broker_rating + 1",
GetSQLValueString($_POST['teamscore'], "int"));

Your form hidden field should be similar to
<input type="hidden" name="teamscore" value="<?php echo $row_nameofrecordset['teamscore']; ?>">

all this is assuming you havea field in your db named teamscore.

hope this helps a little
Inspiring
April 27, 2006
Fantastic !!!!

It works and I've even added anoher button for "minus one point".

Thanks very much for taking the time to help.

Tubby
Inspiring
April 26, 2006
Hi, you would need some update sql similar to the following:

UPDATE table_name SET teamscore = teamscore + 1;

hope this points you in the right direction
Inspiring
April 26, 2006
Thanks for that.

On that basis the code should be

UPDATE teamnames
SET teamscore= teamscore +1;

but how do I turn that into a button on the page?

I've tried using a form and including this code as a hidden field but it didn't work and I'm sure that's too much of a complicated method?

Can you (or anyone else) suggest a better way of doing it so that I can simply click and button or even textlink to apply the code?

Cheers


Tubby