Wolfpack2K All American 7059 Posts user info edit post |
I need a script made for a website I am making.
Ideally, someone could type in a number in a box and press "submit", and it would add to a total. For example, if visitor 1 typed in 20 and visitor 2 typed in 53, then a text message on the page would say "The total entered so far is 73".
If that wouldn't work, then I would like something like the "Pointless Click Counter", where you click a button and it just adds to a total.
Can anyone help? 5/10/2006 4:08:32 AM |
dFshadow All American 9507 Posts user info edit post |
you can do this a lot of ways - a text file is probably the easiest way if you don't wanna make a mySQL database for just one number
i'm assuming this is in PHP 5/10/2006 8:48:05 AM |
dFshadow All American 9507 Posts user info edit post |
if($player1first != "" && $player2first != "" & $player3first != "") { $fo = fopen("players.txt", "r"); while(!feof($fo)) $count=fgets($fo); $count=$count+3; if($subfirst != "") $count++; if($watchingfirst != "") $count++; $fo2 = fopen("players.txt", "w"); fwrite($fo2, $count); fclose($fo); fclose($fo2); } if($count > 90) { $message = "<B>Sorry, max player limit has been reached."; include("message.php"); exit; }
i looked up this code from a basketball tournament registration site i did once5/10/2006 10:55:11 AM |
30thAnnZ Suspended 31803 Posts user info edit post |
^ that's your easiest route right there
and simple as all hell 5/10/2006 11:12:19 AM |
qntmfred retired 40726 Posts user info edit post |
needs more XML
[Edited on May 10, 2006 at 11:38 AM. Reason : or at least some damn AJAX] 5/10/2006 11:37:38 AM |
dFshadow All American 9507 Posts user info edit post |
.
[Edited on May 10, 2006 at 1:04 PM. Reason : brillo pad jokes just don't do it for me anymore. ] 5/10/2006 12:59:00 PM |
tjoshea All American 4906 Posts user info edit post |
^^ gtfo and die 5/11/2006 9:09:15 PM |
Wolfpack2K All American 7059 Posts user info edit post |
So I just need to make a PHP file with that script in it? How do I make it take the number from the input form? And once the PHP file processes it, how do I make it show that on the HTML page? Basically I need to be walked through this thing step by step. Thanks a ton. 5/12/2006 4:43:44 AM |
agentlion All American 13936 Posts user info edit post |
no, that' script is just an example - it won't do what you want. Your's will actually be a lot simpler than that.
i'm sure someone (maybe i will after work) can parse it down to get it doing what you want. All you will need is the PHP file and the text file. You don't need an HTML file, per se - the PHP file (counter.php) is your HTML file. You will point the browser to the php file - domain.com/counter.php - and the PHP script contained in the file will run on the server and send an HTML page to your browser. 5/12/2006 7:04:32 AM |
30thAnnZ Suspended 31803 Posts user info edit post |
i forget that people can't look at simple code and tell what's going on and that an example of something they're trying to do might need to be modified for their specific needs. 5/12/2006 8:33:15 AM |
agentlion All American 13936 Posts user info edit post |
copy paste the following into a file called counter.php. FTP that to your site, and also add a file called counter.txt. In counter.txt just put the number 0, or whatever you want your starting number to be.
<html> <head> <title>Counter</title> </head> <body> <?php if ($_POST['submit']==TRUE) { $newNumber = $_POST['newNumber']; $fo = fopen("counter.txt","r"); $oldTotal = fgets($fo); fclose($fo); $newTotal = $oldTotal + $newNumber; $fo = fopen("counter.txt","w"); fwrite($fo, $newTotal); fclose($fo);
echo "<p>You submitted <span style=\"font-weight:bold;color:red;\">$newNumber</span>.<br> The new total is <b>$newTotal</b>.</p>"; } else { $fo = fopen("counter.txt","r"); $total = fgets($fo); fclose($fo); echo "<p>The current running total is <b>$total</b></p>"; } ?>
<form name="counter" action="counter.php" method="post"> <p>Enter a number to add to the total: <input type="text" name="newNumber" size="3"></p> <p><input type="submit" value="Submit" name="submit"></p> </form> </body> </html>
see demo here - http://joelion.com/temp/counter.php
[Edited on May 12, 2006 at 1:12 PM. Reason : .]5/12/2006 1:10:57 PM |
tjoshea All American 4906 Posts user info edit post |
also make sure whatever user apache is running as has permission to write to counter.txt 5/12/2006 7:32:09 PM |
agentlion All American 13936 Posts user info edit post |
yeah, and only give the URL to the people who need it, or else the total will end up looking like mine (-9.9999999988E+83) 5/13/2006 4:11:07 AM |
IROLA_BLUNT All American 535 Posts user info edit post |
Quote : | "The current running total is 1E+292" |
5/13/2006 9:13:55 AM |
tjoshea All American 4906 Posts user info edit post |
throw a .htaccess in the dir to require login
[Edited on May 13, 2006 at 9:17 AM. Reason : .] 5/13/2006 9:17:13 AM |
moonman All American 8685 Posts user info edit post |
You submitted 3. The new total is 3. 5/13/2006 9:54:04 AM |
agentlion All American 13936 Posts user info edit post |
cool. must have rolled over or something - i didn't reset it. if you don't want to restrict access to the page, you can put in some simple checks to make sure people put in reasonable numbers. First, you can restrict how many digits can be typed in the text box. and 2nd (or in addition to) you can just use the PHP to check the size before adding it to the total and display an error message 5/13/2006 10:10:59 AM |
qntmfred retired 40726 Posts user info edit post |
Quote : | "must have rolled over or something" |
You submitted -1E+292. The new total is 0.
5/13/2006 3:00:17 PM |
Wolfpack2K All American 7059 Posts user info edit post |
AWesome man thank you! One more question - let's say I want to have a button that someone can just clikc and it will add a certain number to the total. Like, every time a visitor clicks this button, it adds 12 to the total.
Furthermore, let's asy I want this button to add to two totals. For example, every time a visitor clicks this button, it adds 12 to Total A and 4 to Total B. How would this work?
Sorry for the elementary questions, I really have no experience at php at all. 5/15/2006 4:55:07 AM |
Wolfpack2K All American 7059 Posts user info edit post |
Nevermind, I figured it out!!!! yay!! 5/15/2006 5:19:37 AM |