Page 1 of 2

storing info in a .txt file

Posted: Fri Mar 19, 2004 6:58 pm
by bawla
This is the code that I have already done.

Code: Select all

<?php
$value1=$_GET&#1111;'value1'];
$value2=$_GET&#1111;'value2'];
$value3=$_GET&#1111;'value3'];
$value4=$_GET&#1111;'value4'];
$username=$_GET&#1111;'username'];
$total1=(($value1 + $value2 + $value3) / $value4);
$total2=$total1 * 10;
echo "<font face=verdana size=2 color=red>&#123;$_GET&#1111;'username']&#125;</font><br>";
echo "<font face=verdana size=2>Games Won </font><br>";
echo "<font face=verdana size=2 color=red>&#123;$_GET&#1111;'value1']&#125;</font><br>";
echo "<font face=verdana size=2>Games lost by someone reaching 100 mojo</font> <br>";
echo "<font face=verdana size=2 color=red>&#123;$_GET&#1111;'value2']&#125;</font><br>";
echo "<font face=verdana size=2>Games lost by zero </font> <br>";
echo "<font face=verdana size=2 color=red>&#123;$_GET&#1111;'value3']&#125;</font><br>";
echo "<font face=verdana size=2>Games Played</font> <br>";
echo "<font face=verdana size=2 color=red>&#123;$_GET&#1111;'value4']&#125;</font><br>";
echo "<font face=verdana size=2>Percent of the time you/someone quit </font><br>";
echo "<font face=verdana size=2 color=red>&#123;$total2&#125;%</font>";
?>
What I want to do with it is to take the

Code: Select all

$total2 and $username
and store it on a .txt file so it has a record of what the % is for people.
I tried using the fopen,fwrite,fclose functions but I just can't seem to get them to work. Also how would I be able to have a top 10 list of the highest %'s. Hopefully this makes sense.
-Peyce

Posted: Fri Mar 19, 2004 7:14 pm
by tim
well you have the right idea with fopen n fwrite functions.

try this

Code: Select all

&lt;?php
$log = "whatever.txt"; 
if(file_exists("$log")) { 
$write = fopen($log, "r+"); 
fwrite($write, $username); 
fclose($write); 
} else { 
echo "$log could not be found"; 
} 
?&gt;
this should write the username...

do you have access to a MySQL database? what you want would be easier if you went thru that

Posted: Fri Mar 19, 2004 7:28 pm
by bawla
where would i put that code? in the same file as the other php code?

and yea i have MySQL but i have no idea how to work it and php seems easier

Posted: Fri Mar 19, 2004 7:32 pm
by tim
i'd suggest you try to learn that... seems your new with php too?

Heres a good tutorial to get you started with both.

A MySQL DB is alot better than a text file when storing info. plus you can arrange, edit, add, delete, etc with stuff in a sql table alot easier then a text file.

http://hotwired.lycos.com/webmonkey/99/ ... rogramming

Posted: Fri Mar 19, 2004 7:34 pm
by tim
u can place the code anywhere after you defined the variables

Posted: Fri Mar 19, 2004 7:36 pm
by bawla
thanks alot man, im gonna get one that tutorial right away

Posted: Fri Mar 19, 2004 7:39 pm
by tim
anytime, and always come back here for help with things you dont understand. Alot of very nice and intelligent people here willing to help.

and your choosing the right path by changing your method to MySQL. you'll thank me in the end.

:D

good luck and godspeed

Posted: Fri Mar 19, 2004 8:06 pm
by bawla
hmm, i stumbled into a little problem, in the tutorial is says to put stuff into the comand line, but i dont know where that is, for MySQL i have phpmyadmin but it doesnt say anthing about that in the tutorial

Posted: Fri Mar 19, 2004 8:08 pm
by tim
by "stuff" i take it u mean the create table?

In phpmyadmin, after u named the table, click the table and you'll see a "sql" link

paste your create table code there

:D

Posted: Fri Mar 19, 2004 8:16 pm
by bawla
wut about the comand line?

it says to put

mysql -u root mydb < mydb.dump

in there

Posted: Fri Mar 19, 2004 8:20 pm
by tim
Oh.. i'm sorry for not explaining...

in the first lessons of that tutorial, it tells u how to set-up php and mySQL on your own server, its thinking your an actual web hoster with the server.

ignore that part, just mimic the table in that tutorial

Posted: Fri Mar 19, 2004 8:23 pm
by bawla
its ok, you've explained way more then you needed too and i thank you for that, you reply to my posts before i even submit them lol

Posted: Fri Mar 19, 2004 8:31 pm
by bawla
i get this error when i try to view the php file that connects to the mysql

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 25
First Name:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 29
Last Name:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 33
Address:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 37
Position:

Posted: Fri Mar 19, 2004 8:33 pm
by tim
read your private message.

and people usually post code so people can see the errors, but it seems like you dont ahve your table set-up correctly.

you connect to your DB before? lets see the code

Posted: Fri Mar 19, 2004 8:41 pm
by bawla

Code: Select all

<?php



$db = mysql_connect("localhost", "root");



mysql_select_db("mydb",$db);



$result = mysql_query("SELECT * FROM employees",$db);



printf("First Name: %s<br>\n", mysql_result($result,0,"first"));



printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));



printf("Address: %s<br>\n", mysql_result($result,0,"address"));



printf("Position: %s<br>\n", mysql_result($result,0,"position"));



?>
thats the code i got form the tutorial,

check your private msg