Home php code that adds a number to the current number or do nothing at it
Reply: 2

# php code that adds a number to the current number or do nothing at it

Mohamed
1#
Mohamed Published in 2017-12-06 11:18:05Z
 My question is very simple i'm programming some sort of an earning site and what i want to add to my php is: when the user type the captcha wrong , number of user coins doesn't increase or decrease but when he types it right , it increases by 100 but the problem i faced is that however the user types it right it doesn't increase after the first time i mean it doesn't go to 200 or more .. and when he types it wrong it turns back into 0 again note: i'm using solve media for the captcha service this is my code $current n = 0; if (!$solvemedia_response->is_valid) { print "
Captcha wrong try again!: ".$solvemedia_response->error." ";$currentn +=0; echo $currentn; }else { print " 100 satoshis have been earned successfuly ";$currentn +=100; echo $currentn; }  David 2# David Reply to 2017-12-06 12:15:02Z  You're not storing the value anywhere. All the code ever does is declare a variable to 0 and then maybe add 100 to it. So all the variable will ever be is 0 or 100. Persist the value somewhere. For example, in session state. Something like this: $currentn = 0; if (isset($_SESSION['currentn'])) {$currentn = $_SESSION['currentn']; }  And when you set the value: $currentn += 100; $_SESSION['currentn'] =$currentn;  You can refactor where you store and retrieve session data depending on how you want to organize your code. But the point is that you need to store the value somewhere. Otherwise every time you load the page it starts again at zero. Edit: I almost forgot, in PHP you also need to start the session service manually before using it. So at the top of any script that uses it you’d need this: session_start(); 
p-a-o-l-o
3#
p-a-o-l-o Reply to 2017-12-06 11:36:03Z
 You need to make the value persist over each postback. You can accomplish this in two way Use PHP session: http://php.net/manual/en/session.examples.basic.php Use some persistent storage on your server (e.g. a database) and save your value there each time it changes (this is very challenging, compared to the former)
 You need to login account before you can post.
Processed in 0.423929 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO