Help with a php form submission
Posted: Sat Aug 07, 2010 6:17 am
Hey guys, I'm very new to PHP, and am creating a small CMS and have it pretty close to working. I have ran into just one problem it seems.
Here's my form code.
Here's the save.php file code
It seems that the "$page" in the fopen() command is not reading from above where I specify it. Everything works great if I just put in a page name in its place but I need it to switch depending on which page is open in the textarea. The code for the $page works perfectly on the form and pulls the correct page. Please let me know if you have questions.
Thanks in advance!
Here's my form code.
Code: Select all
<form action="save.php" method="post">
<textarea id="editor1" name="editor1" rows="10" cols="80">
<?php
$page = $_GET['page'];
if (!empty($page)) {
ini_set("include_path", "../pages/");
$page .= '.php';
include($page);
}
else {
include('../pages/home.php');
}
?>
</textarea>
<br />
<input type="submit" value="Save">
</form> Here's the save.php file code
Code: Select all
<?php
$editor1 = $_POST['editor1'];
$page = $_GET['page'];
if (!empty($page)) {
ini_set("include_path", "../pages/");
$page .= '.php';
include($page);
}
else {
include('../pages/home.php');
}
$ph = fopen($page, 'w') or die ("can't open file");
fwrite($ph, $editor1) or die ("can't write file");
fclose($ph);
?>Thanks in advance!