I am new to PHP so I'm sorry if anything I ask isn't clear. I'm actually a writer, but my boss randomly decided I need to learn PHP so here I am
My first project is to take information from a simple HTML form that asks for users to fill out three text boxes, select if they are user 1 or user 2, and upload a file. I then have to store the information in a text file and display that information in the browser directly below the HTML form. The information must be ordered alphabetically by the first letter of whatever is entered in the first text box. Each entry must be on its own line.
For example:
Person 1 enters: Sally Mae Johnson User 1 Flowers.jpg
Person 2 comes along later and enters: George Michael Johnson User 2 books.jpg
Right now it displays in the order entered like this:
Sally Mae Johnson User 1 Flowers.jpg
George Michael Johnson User 2 books.jpg
I need it to display in alphabetical order by the first letter of the first name like this:
George Michael Johnson user 2 books.jpg
Sally Mae Johnson User 1 Flowers.jpg
I'm so close, but I just can't figure out how to finish it up. If anyone can help they'd be a life saver!
Here's what I wrote so far:
<body>
<?php
$fone = @$_POST["one"];
$ftwo = @$_POST["two"];
$fthree = @$_POST["three"];
$fselect = @$_POST["select"];
if ($_FILES)
{
$name = $_FILES['upload']['name'];
(move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/$name"));
}
//write to the file
$values = "$fone\t";
$values .= "$ftwo\t";
$values .= "$fthree\t";
$values .= "$fselect\t";
$values .= "<img src='uploads/$name'><br />\n";
//open and write to the file
$fp = @fopen("store.txt", "a") or die("Couldn't open the file!");
$numBytes = @fwrite($fp, $values) or die ("Couldn't write values to file!");
@fclose($fp);
?>
<form action="test_it2.php" enctype="multipart/form-data" method="post">
Box 1: <input type="text" name="one" size="15" />
Box 2: <input type="text" name="two" size="15" />
Box 3: <input type="text" name="three" size="15" />
Select One: <select name="select"><option value="empty">Please Select</option><option value="user1">User 1</option>
<option value="user2">User 2</option>
<p>Upload a File:</p>
<p><input type="file" name="upload" />
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="submit" name="submit" value="submit" />
<input type="hidden" name="submitted" value="submitted" />
</p>
</form>
<?php
print "<P>Here are the users:<br />";
$file = "store.txt";
if (file_exists($file))
{
$file1 = fopen("store.txt" , "r");
while (!feof($file1))
{
$display = fgets($file1, filesize("store.txt"));
echo $display . "
";
}
fclose($file1);
}
else
{
echo "<P>Error occured! Please try again!</p>";
}
?>
</body>
</html>