Form..

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sat Apr 23, 2005 7:06 pm    Post subject: Form.. Reply with quote

html :
Code:
<BODY>
<iframe src="storage.php"></iframe>
<form action="storage.php" method="POST">
Type your name:
<input type="text" name="nick" value="Nick" size="20">
<br>Type your comment:
<input type="text" name="message" value="<comment>" size="20">
<br>
<input type="submit" value="Submit">
</form>
</BODY>
</HTML>

Php(storage.php) :
Code:
<html>
<body>

<?php echo $_POST["nick"]; ?>:<?php echo $_POST["message"]; ?>

</body>
</html>

Problem :
When i tested it i clicked the 'submit' button, and got an error :
Error 405

Method Not Allowed

link : http://24.50.158.18:8500/chat.html

And when i just open the page, it asks for me to download the storage.php, which i don't want it to do.

Help is appreciated, Foso :)

edit : I should also add, this is a 'guestbook' feature I want to add to my website, and since I like to do things for myself, I am trying to make my own.

This is my first post, so i would also like to congratulate Aprelium for such a nifty service(Abyss), i can run my server from a floppy! thats awsome.
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sat Apr 23, 2005 9:43 pm    Post subject: Reply with quote

I think you have a problem with your php setup or something.
The page itself worked fine for me, but when I tried it on your server, it prompted me for a download.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sat Apr 23, 2005 10:37 pm    Post subject: Reply with quote

How would i fix that? I installed the Php for abyss and it still doesn't work.
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sat Apr 23, 2005 11:12 pm    Post subject: Reply with quote

FosoFish wrote:
How would i fix that? I installed the Php for abyss and it still doesn't work.


First run a test script to find out of php does actually work...
Code:
<?php
echo "Hello Dave!";
?>

That will do the trick for now. Place it on your server and if it prompts for a download, then it isnt installed properly.

If that is the case, then follow this guide and check your settings.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 2:56 am    Post subject: Reply with quote

Okay, Thanks! i used wrong interpreter, i had version 5, but i was reading torturial for version 4. Used Php.exe instead of Php-cgi.exe. It works, but when i press submit, instead of updating the frame, it brings up another window, how would i fix that? i need the frame to be updated once you press the submit.
Back to top View user's profile Send private message Visit poster's website
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Sun Apr 24, 2005 3:17 am    Post subject: Reply with quote

You need to specify the frame name in a target parameter. In the iframe tag
I had to add name="main" to create a name for the target then edit the form
tag to point to the iframe , hope this information helps you. LateR!

Code:

<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>
<BODY background =" pictures/background.png" LINK =" #616161" VLINK =" #616161">
<style>
BODY {     scrollbar-3d-light-color:#999999;
           scrollbar-arrow-color:#FFFF33;
           scrollbar-base-color:black;
           scrollbar-dark-shadow-color:#333333;
           scrollbar-face-color:#666666;
           scrollbar-highlight-color:#999999;
           scrollbar-shadow-color:black}
</style>
<p><img src =" pictures/beg.png"><a href =" home.html"><img src =" pictures/home.png" border = 0></a><a href =" screen.html"><img src =" pictures/screenshots.png"  border = 0><img src =" pictures/chatroom.png"  border = 0></a><img src =" pictures/logo.png"><img src =" pictures/end.png"></p>
<iframe src="storage.php" name="main"></iframe>
<form action="storage.php" method="POST" target="main">
Type your name:
<input type="text" name="nick" value="Nick" size="20">
<br>Type your comment:

<input type="text" name="message" value="<comment>" size="20">
<br>
<input type="submit" value="Submit">
</form>
<DIV ALIGN="center"></DIV>
</BODY>
</HTML>


Last edited by TRUSTAbyss on Sun Apr 24, 2005 3:23 am; edited 2 times in total
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Apr 24, 2005 3:22 am    Post subject: Reply with quote

TrustPUNK -->
Beat me to it =)

How the hell did you get so fast?
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 3:46 am    Post subject: Reply with quote

Thanks! Not sure if it works yet, I'm on the neighbors laptop. Quick question though, how would i make the php file show all previous additions?
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Apr 24, 2005 3:56 am    Post subject: Reply with quote

FosoFish wrote:
Thanks! Not sure if it works yet, I'm on the neighbors laptop. Quick question though, how would i make the php file show all previous additions?


Youd need to store it to a database, and then return all entires from it.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 4:19 am    Post subject: Reply with quote

If you could give me a link or explanation on how to create a database then retrieve all entries, i would be very grateful :)
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Apr 24, 2005 4:42 am    Post subject: Reply with quote

FosoFish wrote:
If you could give me a link or explanation on how to create a database then retrieve all entries, i would be very grateful :)


If you want to use Mysql...
Firstly, youll need a mysql server (either locally or remotley) to host the database.
Then find a mysql tutorial and take it in =S

If you want help feel free to come and find me on An IM service.

You could also store the entries to a text file and parse the file, but this is a lot less flexible than a database.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 4:52 am    Post subject: Reply with quote

Mysql server, would that count as my abyss local server? or would i need to buy another server?

I'll have to contact you with AIM(once i get home and download the darn thing =/) I really need to learn all this PhP and Mysql.
Back to top View user's profile Send private message Visit poster's website
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sun Apr 24, 2005 5:16 am    Post subject: Reply with quote

FosoFish wrote:
Mysql server, would that count as my abyss local server? or would i need to buy another server?

I'll have to contact you with AIM(once i get home and download the darn thing =/) I really need to learn all this PhP and Mysql.


Mysql is a seperete server which listens to a different port that PHP will connect to when instructed to.
There are plenty of great tutorials around this site if you want more info :-)
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 9:21 am    Post subject: Reply with quote

Okay, just need to set up a database, thanks :)
Back to top View user's profile Send private message Visit poster's website
dellmann
-


Joined: 09 Mar 2005
Posts: 19

PostPosted: Sun Apr 24, 2005 9:46 am    Post subject: Reply with quote

Hi,

With a bit of lateral thinking, I dont think it should be too difficult to store and read the data from a text file. I created a guestbook, and a link manager script recently using only flat files for storage. Its surprising what you can do with them.

Have a look at http://codewalkers.com/tutorials/57/1.html, this tutorial at codewalkers should tell you pretty much everything you need to know, to use text files to store the data for your project.

If you would like some help, let me know, and I can post some code samples from my guestbook app.
Back to top View user's profile Send private message
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 10:56 am    Post subject: Reply with quote

Okay, since Mysql hates me, i decided to use text files.
Code:
<html>
<?php
$fp = fopen( "storage.txt" , "w" );
$Name = $_POST['name'];
$Msg = $_POST['text'];
fwrite( $fp,$Name);
fwrite( $fp, ': ');
fwrite( $fp, $Msg);
fclose($fp)
?>
<body>
<?php
$fp = fopen ("storage.txt", "r");
while (!feof ($fp)) {
    $content = fgets( $fp, 4096 );
echo $content;
}
fclose ($fp);
?>
<form name="content" action="storage.php" method="post">
<INPUT TYPE="text" NAME="name" value = "NickName">
<TEXTAREA NAME="text" value = "Message"><content></TEXTAREA>
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit">
</body>
</html>

link : http://24.50.158.18:8500/storage.php
Problem :
It only saves one line, i need it to have all previous entries =/
Back to top View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Sun Apr 24, 2005 11:26 am    Post subject: Reply with quote

Code:
<?php
$fp = fopen( "storage.txt" , "w" );
$Name = $_POST['name'];
$Msg = $_POST['text'];
fwrite( $fp,$Name);
fwrite( $fp, ': ');
fwrite( $fp, $Msg);
fclose($fp)
?>


The problem is the following line:
Code:
$fp = fopen( "storage.txt" , "w" );

what you are doing is opening the file for writing to ("w"), and this will overwrite anything else that is in that file.

To add something to a file, use the following line:
Code:
$fp = fopen( "storage.txt" , "a" );

the difference? "a" this opens the file and whatever is written to it will be added to the end of the file

Edit: You will also have to add an if() statement to stop the file being written to every time the page is opened
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 12:14 pm    Post subject: Reply with quote

Thanks :). Where should i put the if() though? And what should it check for? sorry, im completely new to PhP =/.
Back to top View user's profile Send private message Visit poster's website
FosoFish
-


Joined: 23 Apr 2005
Posts: 22

PostPosted: Sun Apr 24, 2005 2:39 pm    Post subject: Reply with quote

Help would be appreciated :).
Back to top View user's profile Send private message Visit poster's website
Valle
-


Joined: 23 Apr 2005
Posts: 2

PostPosted: Mon Apr 25, 2005 1:01 am    Post subject: Reply with quote

You could do something like this
Code:
<?php
$filename = 'storage.txt';
// Make sure we're using POST and that $_POST['name'] & $_POST['text'] isn't empy before we write to the file.
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['name']) && !empty($_POST['text']))
{
 $fp = fopen($filename, 'a');
// htmlspecialchars converts <, >, ", & so we can't create HTML, JavaScript, PHP and whatnot
// Trim removes whitespace from beginning and end.
// e.g '   example    ' becomes 'example'
 $Name = htmlspecialchars(trim($_POST['name']));
 $Msg = htmlspecialchars(trim($_POST['text']));
 fwrite($fp, $Name .': '. $Msg .'<br>
');
 fclose($fp);
}
?>
<html>
<body>
<?php
$fp = fopen($filename, 'r');
echo fread($fp, filesize($filename));
fclose ($fp);
?>
<br>
<form name="content" action="storage.php" method="post">
<input type="text" name="name" value="Nickname"><br>
<textarea name="text">Message</textarea><br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group