473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to increase the value of a certain variable with buttons?

..im working on basketball scoring simple program, i need three buttons that has the value of +1, +2, and +3, i want the score to continually increase as each button is clicked..but i always ending up with the value of 1,2,or three, on each button..


can anyone help..please?

Expand|Select|Wrap|Line Numbers
  1. switch ($_POST['basket']) {
  2.  
  3.     case '+1':
  4.     if ($scoreinitial == 0) 
  5.     {    
  6.     $scoreone = $scoreinitial + 1;
  7.     echo $scoreone;
  8.     }
  9.     else {
  10.     $scoreone = $scoreone + 1;
  11.     echo $scoreone;
  12.     }
  13.     break;
  14.  
  15.     case '+2':
  16.     $scoreone = $scoreone + 2;
  17.     echo $scoreone;
  18.  
  19.  
  20.  
  21.  
  22.  
  23. }
  24.  
i use this switch case, but it always return the same values
Feb 7 '11 #1
5 2914
My magic boll says: "use += and not + when calculating".

Does this mean something to you?
Feb 7 '11 #2
Try this:
Expand|Select|Wrap|Line Numbers
  1. switch ($_POST["basket"]) 
  2. {
  3.     case "+1":
  4.         $scoreone++;
  5.         print $scoreone;
  6.     break;
  7.     case "+2":
  8.         $scoreone += 2;
  9.         print $scoreone;
  10.     break;
  11.     default:
  12.         print "Invalid value given.";
  13.     break;    
  14. }
Feb 7 '11 #3
no change at all,if i press the +1 button '1' wil b dsplayd, the same wd +2,evn f i press button repeatdly.
Feb 8 '11 #4
Show me all the code, there might be some logic error before this.
Feb 8 '11 #5
HaLo2FrEeEk
404 256MB
Most likely the score variable is being set somewhere at the beginning of the code, to a static value. If you want it to increase then you need to pass the current score as a GET or POST parameter, or store it in a session variable.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $score = 0;
  3. switch($_POST['basket']) {
  4.   case "+1":
  5.     $score++;
  6.     break;
  7.   case "+2":
  8.     $score += 2;
  9.     break;
  10.   case "+3":
  11.     $score +=3;
  12.     break;
  13.   }
  14.  
  15. echo $score;
  16. ?>
No matter how many times you run this you're gonna get either 1, 2, or 3, depending on the value of the "basket" POST value.
Feb 9 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Shapper | last post by:
Hello, I have a database table with 2 fields: and ; I need to create a function which increases by 1 the number in field for a certain id. In this moment I have the following: Private...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
3
by: indra061 | last post by:
Hi all, I am newbie of perl. The story is, i need to read and update one variable from text file (WARPFREQ = 0.88). The value of WARPFREQ will be inceremented by 0.2 up to 1.2. Everytime the...
2
by: Cliff | last post by:
Hi, i would like to get the value of variable 'em', defined in code-behind, into a textbox. I tried two ways but withoit succes (no error). The first textbox is empty, the second gets:<%=em...
6
by: trungthanh78 | last post by:
Hello everyone, I'm totally new to the group and I would like to learn from you. Thank you in advance! I need to write a program to track whether a mathematical function has changed during...
41
by: jpmcafee | last post by:
Hi Guys, Iam new to vb2005 and programming and I could really use some help. I have finished my book on vb2005 and i cant find what I am looking for, Essentially I want to create...
4
by: kat248637 | last post by:
suppose i have a variable in shell script like a="prashant" and i want to assign this variable into another variable like b=$a,which is in perl script.after run perl script the value of b should be...
3
by: brendanmcdonagh | last post by:
Hi, I have a datatable being populated in a for each loop and it's working great. I'm now trying to eradicated duplicates, I have set productid as uniques and it throws an exception when another...
1
by: didacticone | last post by:
i have an unbound text box on a form with '0' entered in it. i also have another text box linked to my table. what i would like to is when the linked text box (dayoff) has a certain criteria entered...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.