Jump to content

Recommended Posts

Heya

 

I would love to be able to have something where by users can paste their current status to be viewed by other users. To be more specific I would like a user to be able to input his/her name, level achieved and in which skill. So other users can find it easier to find hunting groups.(mmorpg related ). Preferably the data could be saved in a text file.

 

Perhaps an input feild at the top of the block would look somethingn like:

 

Name: [input field] Level: [input field] Skill: [input field]  Send (button)


Monje reached level 230 in Melee.

Yakapo reached level 250 in Offensive Affliction.

Jenny reached level 64 in Desert Forage.


 

This could perhaps be used to great effect in a more general way to quickly check the status of forums users.

 

Any help on this would be much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/144463-request-help-with-user-status/
Share on other sites

Im trying to get to grips with what i need.

So far:

formdata.txt  where the 3 bits of data will be stored.

formdata.php where the php code to append the data to the formdata.txt file

 

and the form markup, with an iframe underneath the form displaying the contents of the formdata.txt file.

 


<form enctype="multipart/form-data" action="uploader.php" method="POST">

<input type="text" size="5" name="user" value="User" /><input type="text" size="5" name="level" value="Level" /><input type="text" size="5" name="skill" value="Skill" /><input type="submit" value="Send" height="2" />

</form>
<hr />

 

 

I have no idea where to start with the php code to apply the form data to the text file though . any help would be much appreciated.

Ive tried the folowing code in the formdata.php file:

 

<?php

$myFile = "formdata.txt";

$fh = fopen($myFile, 'a') or die("can't open file");

 

fwrite($fh, $_POST['user'],$_POST['level'],$_POST['skill']);

 

fclose($fh);

?>

 

I thought this would  post the 3 bits of data in the form but im clearly missing something.

Ive managed to come up with this:

 


<html>
<head>
</head>
<body>

<form enctype="multipart/form-data" action="form.php" method="POST">

<input type="text" size="5" name="user" value="User" /><input type="text" size="5" name="level" value="Level" /><input type="text" size="5" name="skill" value="Skill" /><input type="submit" value="Send" height="2" />

</form>
<hr />


<?php
$myFile = "formdata.txt";
$fh = fopen($myFile, 'a') or die("can't open file");

fwrite($fh, $_POST['user']);

$stringData = " reached level ";
fwrite($fh, $stringData);
fwrite($fh, $_POST['level']);

$stringData = " in ";
fwrite($fh, $stringData);
fwrite($fh, $_POST['skill']);

$stringData = ".<br />";
fwrite($fh, $stringData);

fclose($fh);
?>


<?php
$myFile = "formdata.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 10000);
fclose($fh);
echo $theData;
?>

</body>
</head>



 

It seems to work well for what i need, but can anyone help me with getting the latest submissions at the top, instead of at the bottom?

If you use file to retrieve/display the file you can do an rsort on the array and it will reverse it so the top is displayed first. No need to rewrite the whole thing when you can simply re-organize it quick and easy.

 

Assuming that the data is broken up by a line break ("\n"), that would work.

 

If that is not an option, you will have to re-write the whole file each time a new entry is entered, which increases processing time quite a bit more and is more prone for collision errors due to the file having to be open for a bit longer.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.