Page 1 of 1

Help with a php form submission

Posted: Sat Aug 07, 2010 6:17 am
by Mauisnow13
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.

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); 
?>
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!

Re: Help with a php form submission

Posted: Wed Aug 11, 2010 3:10 pm
by Jsphlane20
Echo the value of $page right before you utilize the function fopen and ensure that the value that it returns is the correct syntax. Reply with results.

Re: Help with a php form submission

Posted: Fri Aug 13, 2010 1:08 am
by Mauisnow13
It didn't return anything. On the index.php page, it correctly posts the value as it should. In this code, it doesn't work, I'm pretty sure because those includes just don't work with the code.

It's a problem with this part.

Code: Select all

$page = $_GET['page'];
	if (!empty($page)) {
		ini_set("include_path", "../pages/");
		$page .= '.php';
		include($page);
	}
	else {
		include('../pages/home.php');
	}
It works fine when it's all by itself, and I essentially need that same effect, except without including. Instead of include, I need those to be the values that "$page" can mean.

That way, if it finds the value (let's say "services") in the URL, it will load whichever php page the URL says, which is located in the "../pages/" folder. Which would be "../pages/services.php". Otherwise it loads "../pages/home.php". Hope this makes sense.

Thanks

Re: Help with a php form submission

Posted: Sat Aug 21, 2010 2:58 pm
by Mauisnow13
Anyone?