help in php coding

Status
Not open for further replies.

*GandaBerunda*

Drool!...Vista
i am having a textbox and a button on my website..i want whatever the user enters in da box to be saved to a textfile on the server...how can i do so?
after writing it should automatically redirect to another address....can someone please guide me?
i think i can do this by opening a php file using "OnClick" and then redirecting thorugh the php file after the data has been written.....can someone please give me the complete code?
this is the code tat i get when i click on the button in ms expression web
<input name="Button1" type="button" value="Sign in">
and the name of the textbox is text1

pleaze give me the entire code if i want to write the text to a file in the dir
*xxxx.xxxx.com/text.txt
 

Sukhdeep Singh

Host4Cheap.org
No need to open nother account. You could have posted in your old topic regarding problems you faced :)
*www.thinkdigit.com/forum/showthread.php?t=68950
 

[xubz]

"The Cake is a Lie!!"
Heh :p

Coded this in 15mins, So Post back if you get any Errors

3 Files
1) test.html
2) test.php
3) text.txt

test.html
PHP:
<form action="test.php" method="post">
	<input type="text" name="tbName" /><br />
	<input type="submit" name="btnSubmit" value="Submit" />
</form>

test.php
PHP:
<?php
//Check if the Form is Posted
if (isset($_POST))
{
	$success = false;

	//Validate the Fields
	if ((isset($_POST['tbName']) && $_POST['tbName'] != '') &&
		(isset($_POST['btnSubmit']) && $_POST['btnSubmit'] == 'Submit'))
	{
		$fcontents = file_get_contents('./text.txt'); //Get the Contents of the File
		if (is_writable('./text.txt')) //Check if the File is Writable
		{
		    //Open the File and fput the contents. (Don't forget to add CR+LF)
			$fp = @fopen('./text.txt', 'w');
			@fputs($fp, $fcontents);
			@fputs($fp, $_POST['tbName']);
			@fputs($fp, "\r\n");
			@fclose($fp);

			$success = true; //Set Success Boolean to true
		}
		else
		{
			echo 'File not Writable';
		}
		
		//If Success is true, then Redirect to a Different Page
		if ($success)
		{
			$redir_page = './test.html'; //Can be set to *gmail.com/, etc.
		    header('Location: ' . $redir_page);
		}
	}
	else
	{
		echo 'Please Fill all the Fields';
	}
}
?>

text.txt
Code:
Data
-----
(Don't forget to add a blank like at EOF)


The script maybe a little inefficient, but it can be modified :)

(Yeh! I had some time to waste :( )
 
Status
Not open for further replies.
Top Bottom