I want to make a basic link directory taht fits very easily into my current design (
www.kaziaz.com).
What I want is this:
Someone fills out a form Putting in this:
URL (text field)
Their Name (text field)
Description (text area)
Category (drop-down menu)
If for example they put this in:
URL =
www.google.com
Their Name = Bob
Description = A cool SE.
Category = General
Then In A File called "general.txt" a new line is generated which contains the Url their name and the description.
Then back on the directory there would be a link to the General Category and in there would be a list of the links in the general.txt file with the submitters name and Descrition beneath...
Is that possible?
Or am I gonna have to use a database?
Comments
if your going to write to a text file you will need to take a look at the fopen and fwrite functions
The Royal Ram
Or maybe you just want to code it for me?
A text file will not be able to support you site if your users increase. If you have 1 text file per category, you'll have a big headache maintaining so many text files. If you have 1 text file for all the categories, you'll have a very inefficient and complex script. The 1 text file design will also not be able to cater for multi-access.
But using MySQL on my server? No chance! lol
Anyway... I tried to have a go myself and this is what I did:
I made an "Add" page which looked like this:
I made a php page to process the info in the form:
I also made a file called 1.txt which is where the stuff whould be written to.
The error I get is:
Can anyone tell me what I ahve done wrong... Or if its quicker, maybe you could tell me what I did right? lol.
Thanks in advance!
have the input fields you have, and just have a pretty basic php script to right to the .txt
This is going to be the HTML form to gather the info. Now we need a pretty basic PHP script to gather this information...
This opens the file, and if it cant, use the if and else statements, if it can, write to the file, and then close it. You can edit this, just dont change much to it...
[php]
$file = 'links.txt';
$cat = $_POST;
$name = $_POST;
$url = $_POST;
$site = $_POST;
$desc = $_POST;
if($_POST) {
if(!file_exists($file) || !is_writable($file)) {
echo 'Make sure the file '.$file.' is writable by the server and does exist.';
}else{
$string = "$cat\t";
$string .= "$name\t";
$string .= "$url\t";
$string .= "$site\t";
$string .= "$desc\n";
$fp = fopen($file,'a');
fputs($fp,$string);
fclose($fp);
echo 'done...';
echo $string.' Written succesfully.';
}
}
[/php]
Now thats a rather simplistic script. In order to handle more than one person accessing the file at one time look into the flock function.
I have never been too needy but I lost my job due to the company shutting down our location. I just had a child and live in a pretty depressed area at the moment. I need some freelance work fairly bad.
I have never been too needy but I lost my job due to the company shutting down our location. I just had a child and live in a pretty depressed area at the moment. I need some freelance work fairly bad.
I have never been too needy but I lost my job due to the company shutting down our location. I just had a child and live in a pretty depressed area at the moment. I need some freelance work fairly bad.
You changed the line that is written to the txt file by putting tabs in so that If I want, I can display each bit of info seperately by using a fuction called explode?
Can anyone explain the tabs and explode () thing?