03-09-2011, 02:33 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Feb 2010
Posts: 69
Thanks: 16
|
Creating and calling functions
Ok so now im at the next level where i need to take it to the next step. Over the past i have used Multiple pages for scripts etc.. now what i need to do is put them all on the same page rather than having to redirect place to place then to redirect back to the original page. Only thing is im having trouble on how to construct what i have and looking at examples once again getting confused. So if someone could show me how to construct this.??
Ok so on the main page i have:
PHP Code:
<?php
$myFile = "../includes/docs/sdata.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo '<form action="Scripts/edittemplates.php" method="post" enctype="multipart/form-data"><label for="templateedit">Edit template script</label><br /><textarea name="templateedit" cols="90" rows="20" id="templateedit">' . $theData . '</textarea><br><br><button>Save Template script</button></form>'
?>
Its basicaly just displaying what i have in that text file... with a button that submits the change. The button takes you to the file Scripts/edittemplates.php which contains the code to edit the file and put on there the new content.
PHP Code:
<?php
//lets delete old file
$myFile = "../../includes/docs/sdata.txt";
unlink($myFile);
//now create a new 1
$ourFileName = "../../includes/docs/sdata.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
//now write the data
$thescript = $_REQUEST["templateedit"];
$myFile = "../../includes/docs/sdata.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "" . $thescript . "";
fwrite($fh, $stringData);
fclose($fh);
//pend to admin log
$ip=$_SERVER['REMOTE_ADDR'];
$myFile = "../../includes/docs/adminlog.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "<div class='qname'>sb0t Template script edited by: " . $ip . " at: " . date("d-M-Y-h-i-a") . "</div><hr class='custhr' />";
fwrite($fh, $stringData);
fclose($fh);
header( 'refresh: 0; url=http://www.sb0t.tentun.co.uk/Admin/edits.php' );
echo '<div class="motdadded"><h3>Template script edited...</h3></div>';
?>
And then redirects back to the original page... so now what i need to do is put this in to the 1 page only but have no idea how to construct it and how to call it from the form so could someone edit this and construct it to see how such a thing would be done? Thanks! would appriciate it a lot so i can see how it works.
|
|
|
|