how to make a good and bad button

hi all i currently have this.
[php]

<?php $file='bad.txt'; $bad=file_get_contents($file)+1; file_put_contents($file,$bad,LOCK_EX); ?> <?php echo $bad;echo "bad"; ?>
<?php $file='good.txt'; $good=file_get_contents($file)+1; file_put_contents($file,$good,LOCK_EX); ?> <?php echo $good;echo "good"; ?>
[/php]

this gives me a good and bad button then when i push it gives me a count but when ever i press good it also changes the bad counter how would i make this change so it changes only the good when i press good.

  1. when ever i refresh the page it added another count how i stop this.

  2. i currently have this setup on a txt sheet but would i be better off putting it in a database if so how would i go about doing this.

thanks in advance all.

Hi mate, i’m a beginner at this aswell. However i do use a Mysql db instead of a txt file.
setting all this up with a apache server, php and a mysql database can be a little tricky.
but reading the walktroughs is the key, im sure you will be able to figure this out pretty fast.

if you dont want all the work and just need something to play and test localy i think MoWeS is a nice toy, free above that. www.mowes.chsoftware.net

i can’t give you the complete coding here on how to change your script to saving in a db. but since you made your last script im sure you will be able to figure out the coding to save in a DB.
googeling for snippets has been a geat help for me. i can say i have more trouble with how to use the php correctly then creting the code for reading or saving to the db. that part is pretty straigth forward.

hope i’ve been helpfull ;).

After you make the change, unset the file variable. That way, the information isn’t sitting in memory.

[php]$file=‘bad.txt’;
$bad=file_get_contents($file)+1;
file_put_contents($file,$bad,LOCK_EX);
unset($file, $bad);[/php]

Do the samething for the good button.

Sponsor our Newsletter | Privacy Policy | Terms of Service