...

View Full Version : php submit need



krissyafc
06-03-2007, 11:31 AM
I am making a site and its almost done.

I need a textbox and submitt next to it. What erver somone puts in the box and clicks submitt goes to a html file on the server. And every time something else is added via the text box it takes a new line and i have a collection of data users have said.

After it happens i need it to take them to a page on the server.

If you can when the data is on the page there will be a delete on next to it so i can delete them without editing. THERE must be a new line.:thumbsup: :)

Thanks,

rafiki
06-03-2007, 11:49 AM
<?php
if (!isset($_POST['add'])){
?>
<form name="test" action="add.php" method="post">
<textarea name="add" rows="10" cols="30"> Here is an example </textarea>
<input type="submit" name="submit" value="submit" />
</form>
<?php
}else{
$text = $_POST['add'];
$f = your.txt;
$h = fopen($f, r);
$contents = fread($handle, filesize($filename));
$contents = '' .$text.'<BR/>'.$contents;
$a = fwrite($h, $content)
if ($a){
header("Location: http://www.site.com/somedir/page.php");
}else{
echo "error";
}
}
and get the contents of your.txt and echo it out into page.php

krissyafc
06-03-2007, 11:58 AM
it wont work.

Is that all the code?

matak
06-03-2007, 12:17 PM
Try this


<form action="" method="post">
Title:
<br />
<input type="text" name="title" size="53">
<br />
Text:
<br />
<textarea name="text" rows="20" cols="40"></textarea><br />
<br />
<input type="submit" value="Save">
</form>
<?php

if (@$_POST['title']=="" || @$_POST['text']==""){
echo "Enter text to save!";
}
else {
//this is path to file
$filename = './postit.html';
//i used $title to strip HTML/PHP tags < >, and added <h2> HTML tag to decorate title
$title = "<h2>".strip_tags($_POST['title'])."</h2>\n";
//with this $_POST['text'] is stripped from html/php tags like title, but also preg_replace
//is used to replace \n(every enter that u hit when writing tekst),
//and instead of that added <p> tags which decorate your new paragraph
$tekstmanage = preg_replace('/\n/','</p><p>', strip_tags($_POST['text']));

//i should probably write a whole preg_replace function instead, which i will probably later,
//but this $tekst variable is used to add finishing and closing tags
//to our tekst manage. you can see how preg_replace adds first closing than starting tags
//and with this we just simply add starting before closing and closing after starting tags :confused: ;)
$tekst = "<p>".$tekstmanage."</p>\n";

//after our variables are defined, we combine them in unique variable which we'll write to file
$content = $title.$tekst;

//This below is basic write to file function that i found on php.net, and rearanged
//i'll just explain it briefly
//
//this checks weather our filename is writeable (on unix systems like here on trap17)
//you need to change permissions to the file that allows writing to world 646
if (is_writeable($filename)){

//if file cant be opened to add -> 'a' <- in the fopen construct
//just echo sorry
if(!$handle= fopen($filename,'a')){
echo "Sorry, you can't write to file1";
}
//if file cant be written to, same
if (fwrite($handle, $content) === FALSE){
echo "Sorry, you can't write to file2";
exit;
}
//if both of those terms are fine just echo the confirmation text
echo "You wrote to file ".$filename."<br />";
echo "<a href=\"postit.html\">View</a>";

}
else {
echo "Sorry, you can't write to file3";
}
}

?>

Be sure to have postit.html in the same directory :rolleyes:

rafiki
06-03-2007, 12:26 PM
no it wasnt the full code, it was example code, do you want somebody to do work for you for free?

krissyafc
06-03-2007, 12:57 PM
http://krissyafc.110mb.com/reg/reg.php

I only want a small code...

http://krissyafc.110mb.com/reg/reg.php it wont work

What i need is a script that users can put the email in then it will go to a html for each email and take a new line on each new email added. No SQL.

Then it will take them to another page.

matak
06-03-2007, 01:01 PM
u'r missing something in my code.. < at the begening..

btw, the logic is in the code, weather it to be a title or, email, or bunch of other things, just add them in form, and PHP part.

Like rafiki said, users here will help you, but won't do the job for you...

krissyafc
06-03-2007, 01:49 PM
I get: Unable to write file 3?

rafiki
06-03-2007, 01:52 PM
chmod it to 0755
http://uk2.php.net/chmod

krissyafc
06-03-2007, 02:03 PM
Still the same.

All it is is a sign up to our mailing list thing then I ceck it every day and add new ones to the list.

rafiki
06-03-2007, 02:14 PM
does the file exist and is it in the correct folder, ./postit.html the dot/period makes it go UP a directory

matak
06-03-2007, 03:43 PM
I get: Unable to write file 3?

filename isn't writable. chmod file to 777. if you don't know how to chmod..

rafiki
06-03-2007, 04:27 PM
filename isn't writable. chmod file to 777. if you don't know how to chmod..

according to php.net/chmod you should use 0777 (octal value) and should set it to 0755 for Everything for owner, read and execute for others



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum