Jump to content

very simple cms form problem


amplexus

Recommended Posts

Hi,

I'm creating a website, and want to have text on a portion of each page be editable by a non-tech, average user.  I've created a form, and I've got it to work. I'm using .txt files.

 

wht I've tried to do is create one page that has all of the pages' editable areas on it, each one displaying the current text, and a submit button to make the changes live.

 

Problem:  when you click any of the submit buttons, all of the areas update.

 

here;s my code

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

 

<body>

Edit copy for Homepage to appear as you want on the website, then click "update"

<?

if($_POST['Submit']){

$open = fopen("index.txt","w+");

$text = $_POST['update'];

fwrite($open, $text);

fclose($open);

echo "<br /><br /><br />File updated to:<br /><br /><br />";

?>

<a href="../index.php">View Live Results</a><br /><br /><br />

<?

$file = file("index.txt");

foreach($file as $text) {

echo $text."<br />";

}

}else{

$file = file("index.txt");

echo "<form action=\"".$PHP_SELF."\" method=\"post\">";

echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";

foreach($file as $text) {

echo $text;

}

echo "</textarea>";

echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n

</form>";

}

?>

Edit copy for About Us page to appear as you want on the website, then click "update"

<?

if($_POST['Submit']){

$open = fopen("about.txt","w+");

$text = $_POST['update'];

fwrite($open, $text);

fclose($open);

echo "<br /><br /><br />File updated to:<br /><br /><br />";

?>

<a href="../about.php">View Live Results</a><br /><br /><br />

<?

$file = file("about.txt");

foreach($file as $text) {

echo $text."<br />";

}

}else{

$file = file("about.txt");

echo "<form action=\"".$PHP_SELF."\" method=\"post\">";

echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";

foreach($file as $text) {

echo $text;

}

echo "</textarea>";

echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n

</form>";

}

?>

Edit copy for Rental Property Page to appear as you want on the website, then click "update"

<?

if($_POST['Submit']){

$open = fopen("rental.txt","w+");

$text = $_POST['update'];

fwrite($open, $text);

fclose($open);

echo "<br /><br /><br />File updated to:<br /><br /><br />";

?>

<a href="../rental.php">View Live Results</a><br /><br /><br />

<?

$file = file("rental.txt");

foreach($file as $text) {

echo $text."<br />";

}

}else{

$file = file("rental.txt");

echo "<form action=\"".$PHP_SELF."\" method=\"post\">";

echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";

foreach($file as $text) {

echo $text;

}

echo "</textarea>";

echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n

</form>";

}

?>

Edit copy for Crew to appear as you want on the website, then click "update"

<?

if($_POST['Submit']){

$open = fopen("crew.txt","w+");

$text = $_POST['update'];

fwrite($open, $text);

fclose($open);

echo "<br /><br /><br />File updated to:<br /><br /><br />";

?>

<a href="../crew.php">View Live Results</a><br /><br /><br />

<?

$file = file("crew.txt");

foreach($file as $text) {

echo $text."<br />";

}

}else{

$file = file("crew.txt");

echo "<form action=\"".$PHP_SELF."\" method=\"post\">";

echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";

foreach($file as $text) {

echo $text;

}

echo "</textarea>";

echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n

</form>";

}

?>

Edit copy for Order Lobsters to appear as you want on the website, then click "update"

<?

if($_POST['Submit']){

$open = fopen("order.txt","w+");

$text = $_POST['update'];

fwrite($open, $text);

fclose($open);

echo "<br /><br /><br />File updated to:<br /><br /><br />";

?>

<a href="../order.php">View Live Results</a><br /><br /><br />

<?

$file = file("order.txt");

foreach($file as $text) {

echo $text."<br />";

}

}else{

$file = file("order.txt");

echo "<form action=\"".$PHP_SELF."\" method=\"post\">";

echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";

foreach($file as $text) {

echo $text;

}

echo "</textarea>";

echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n

</form>";

}

?>

 

</body>

</html>

 

 

what's wrong?

Link to comment
https://forums.phpfreaks.com/topic/265973-very-simple-cms-form-problem/
Share on other sites

If you want help, you should make it easy for those who might try to help you. People aren't likely to pore over a wall of unformatted code. Indent it properly, and post it within the forum's

 . . . 

BBCode tags and you'll probably get some responses.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.