Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

button to add one to database total

Explorer ,
Apr 25, 2006 Apr 25, 2006
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
TOPICS
Server side applications
325
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 25, 2006 Apr 25, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 26, 2006 Apr 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2006 Apr 27, 2006
Can anyone out there help me. I've still struggling with this one
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2006 Apr 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 27, 2006 Apr 27, 2006
LATEST
Fantastic !!!!

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

Thanks very much for taking the time to help.

Tubby
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines