...

View Full Version : PHP Submit



van21691
04-13-2008, 03:50 AM
I do not know what its called but basically it is a form. It is more than a form.
It's hard to explain.
Let's say that I have two files: info.txt/info.dat and form.php.
In form.php, I have the form code, then when you view it and test it and make something up. I want all the data that was submit to go inside the info.txt file.

If i am not clear, please reply. Thank you

BTW: this is not to phish someone, but this is for my school club website that I am doing.

Iszak
04-13-2008, 03:54 AM
You'll want to the fread, fwrite commands, this way you can save data into the file, but I'll have a character that seperates each submit like a linebreak or something so when you're parsing it you can seperate it.

van21691
04-13-2008, 03:55 AM
could you post on how would I do that.
Thank you

van21691
04-13-2008, 05:15 AM
This is what I got from the net. Basically, what this do is after you hit submit, it will replace whatever is in the info.dat. What I want is instead of replacing what is in the info.dat, I want to put more

<?
$newcontents="This
is my content"; //
$filename="info.dat";

$fp = fopen ($file_name, "w");


fclose ($fp);

chmod($file_name,0777);

?>
<html>
<head>
<title>File Editor Test</title>
</head>
<body>
<h1>File Editor Test</h1>

<?php
$newcontents = $contents;
if(isset($_POST['submit'])) { //if submit was pressed
$writefh = fopen($filename, "w"); //File handle for $filename

if(get_magic_quotes_gpc()){
$newcontents=stripslashes($_POST['editcontents']);
} //strips unneeded backspaces by magicquotes
else{
$newcontents = $_POST['editcontents'];
}

//NEXT 3 LINES ARE THE PROBLEM SPOT:
fwrite($writefh, $newcontents, strlen($newcontents)); //Saves changes
rewind($readfh); //resets cursor in file

echo("The changes were saved.<br/>\n");
fclose($writefh);
}
?>
Edit the file here:
<form method="post" action="<? echo($PHP_SELF); ?>">
<textarea name="editcontents" style="width:400px; height:150px;"><? echo($newcontents); ?></textarea>
<br />
<input type="submit" name="submit" value="Save Changes" />


</form>
</body>
</html>

_Aerospace_Eng_
04-13-2008, 05:32 PM
Change this

$fp = fopen ($file_name, "w");
to this

$fp = fopen ($file_name, "a+");
There are other things you could use. I suggest you read the manual on whats available.
http://us.php.net/manual/en/function.fopen.php

van21691
04-14-2008, 12:16 AM
thanks for the help. i got it now
Thank you



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum