homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Add +1 to the $num?
PHP math help!

 7:22 pm on Feb 2, 2008 (gmt 0)

I need a code that adds +1 to a number. But I need that number thats being added to be stored some how so that at every time someone presses the "submit" button it will add +1 to the current number.

So if the number is 50 it will add 1 to that equaling 51 and then if another person does presses the submit button it goes from 51 to 52.

Is there anyway to do this? and if so can you show me how?



 7:48 pm on Feb 2, 2008 (gmt 0)

// let's add 1
// new val
echo"$my_val= " .++$my_val;
// should be 2
search: php incrementing
There is quite a few ways to get that result


 8:24 pm on Feb 2, 2008 (gmt 0)

I would store the number in a file.

something like this:

if ( isset( $_POST['some form variable here'] ) ) {

$current_count = file_get_contents( 'count.txt' );
$handle = fopen( 'count.txt', 'w' );
fwrite( $current_count, $handle );
fclose( $handle );



 11:00 pm on Feb 2, 2008 (gmt 0)

How would I incorperate that into this:

$name = $_POST['name'];
if(isset($name, $gamename, $contact, $code1, $code2, $code3, $country, $card, $bio)) {
$fp = fopen("/home/www/poketech.net/site/wi-fi/users/$current_count.php","a");

echo "<br><center>Your page is here: <a href=/site/wi-fi/users/$current_count.php>http://example.net/site/wi-fi/users/$current_count.php</a></center>";

echo "$count";

fputs($fp,($header).'<?PHP include("/home/www/example.com/top.php");?>');
fputs($fp,nl2br($center).'<table border="1"><tr><td>Username:</td><td>');
fputs($fp,nl2br($name).'</td></tr><tr><td>Game Name:</td><td>');
fputs($fp,nl2br($contact).'</td></tr><tr><td>Friend Code:</td><td>');
fputs($fp,nl2br($country).'</td></tr><tr><td>Trainer Card:</td><td><img src="');

I have a page called add.php and then this is where everything takes place in the process.php, so the visitor fills out the form and it creates a page in the "/users/" directory but then I want it to have a number in the url so like "http://example.net/site/wi-fi/users/1.php" and then the next visitor that makes a page it will have and url like this "http://example.net/site/wi-fi/users/2.php" so it adds one each time. But I couldn't get it to work so that it would add 1 to it each time...

Any suggestions on how to do that? Or you can just fix the code above.

[edited by: PokeTech at 11:02 pm (utc) on Feb. 2, 2008]

[edited by: eelixduppy at 6:39 am (utc) on Feb. 3, 2008]
[edit reason] please use example.com [/edit]


 12:42 pm on Feb 3, 2008 (gmt 0)

I think that you might need to take a look at your logic
you could have in your DB a table with three cols

page_id is auto-incremented so you do not have to bother about its #id

user_id is the result of a query on user's table and inserted in the new table (you might at some point need it!)

page address: aaaaaa.com

Sysytem: query the new table grab the last page id
the final address to insert will be a concataination [w3schools.com] of page_address and page_id+1

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved