Jump to content


Photo

PHP code error


  • Please log in to reply
5 replies to this topic

#1 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 09 June 2006 - 06:49 PM

Okay, this PHP code i'm using in the register part and the part of code that counts users dosen't work (It resets the number of users to 1)
$file=@fopen"_private/num_of_users.txt","r" or die"Sorry profile couldn't be created";
    $num_users=@fread($file,filesize($file));
    
    $num_users=$num_users+1;
    @fclose$file;
    
    $file=@fopen"_private/num_of_users.txt","w+" or die"Sorry profile couldn't be created";
    @fwrite$file,$num_users;
    @fclose($file);
        
    
    $file=@fopen$newfilename2,"w+";
    @fwrite$file,$num_users;
    @fclose$file;
I know I don't have () in the functions
Please help


Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 09 June 2006 - 06:53 PM

Tried adding () ...?
I think it's the only problem.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 fert

fert
  • Members
  • PipPipPip
  • Advanced Member
  • 1,114 posts

Posted 09 June 2006 - 06:59 PM

[!--quoteo(post=381999:date=Jun 9 2006, 12:53 PM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 9 2006, 12:53 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Tried adding () ...?
I think it's the only problem.

Orio.
[/quote]
No i took out the () so the forums would let post code

EDIT: I found the problem in the fread part the second argument wasn't the right file.

Si hoc legere scis nimium eruditionis habes
Gentoo Linux 2007.0 Firefox 2

#4 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 07:08 PM

use file_get_contents instead of fopen, fread... and why are you writing to a new file at the bottom? Also, you might want to put quotes "" around your $num_users variable when you write it to the file. Like: @ fwrite [$file, "$num_users"]
[table]



Don't worry, the printer fairies will sort it out.

#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 09 June 2006 - 07:09 PM

[!--quoteo(post=382004:date=Jun 9 2006, 12:08 PM:name=Fyorl)--][div class=\'quotetop\']QUOTE(Fyorl @ Jun 9 2006, 12:08 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
use file_get_contents instead of fopen, fread... and why are you writing to a new file at the bottom?
[/quote]
file_get_contents was added as of PHP 4.30..

Anyways, he fixed it [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
~ D Kuang

#6 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 07:22 PM

[!--quoteo(post=382005:date=Jun 9 2006, 02:09 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Jun 9 2006, 02:09 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
file_get_contents was added as of PHP 4.30..

Anyways, he fixed it [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
[/quote]
A lot of functions were added as of PHP 4, doesn't mean we should only use PHP 3 functions...
[table]



Don't worry, the printer fairies will sort it out.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users