Help with a php form submission

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mauisnow13
Forum Newbie
Posts: 3
Joined: Sat Aug 07, 2010 6:05 am

Help with a php form submission

Post 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!
Jsphlane20
Forum Newbie
Posts: 17
Joined: Wed Aug 11, 2010 1:17 pm
Contact:

Re: Help with a php form submission

Post 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.
Mauisnow13
Forum Newbie
Posts: 3
Joined: Sat Aug 07, 2010 6:05 am

Re: Help with a php form submission

Post 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
Mauisnow13
Forum Newbie
Posts: 3
Joined: Sat Aug 07, 2010 6:05 am

Re: Help with a php form submission

Post by Mauisnow13 »

Anyone?
Post Reply