Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Creating a simple page that updates using textarea content

Featured Replies

This is for a personal university project for a club. Basically the main page needs to have new content added by members of the club. The club is only on the university network so security isn't a huge issue.

 

<html>
<head>
</head>
<body>
<form name="form1" method="post" action="save.php?saving=1">
<textarea id="date" name="date" cols="10" rows="1">
<textarea id="author" name="author" cols="10" rows="1">
<textarea id="post" name="post" cols="60" rows="1">
</textarea>
<input type="submit" value="Save">
</form>
</body>
</html>

 

There's the HTML code, currently the PHP code can save the value within the data textarea but won't add the other text fields.

 

 

<?php
$saving = $_REQUEST['saving'];if ($saving == 1){

$date = $_POST['date'];$dateposted = date("Ymd");
$file = "$dateposted.html";
$fp = fopen($file, "w") or die("Couldn't open $file for writing!");fwrite($fp, $date) or die("Couldn't write values to file!");
fclose($fp);echo "Saved to $file successfully!";

}
?>

 

At the moment the PHP creates a new file everytime. What I would like it to do is add the value of the 3 seperate contents of the textareas to a HTML page where they would then get put into 3 newly created divs each time.

 

so

 

<div id="date">

textarea1 goes here

</div>

 

<div id="author">

textarea2 goes here

</div>

 

<div id="post">

textarea3 goes here.

</div>

 

Then for it to re-add these divs each time so if you added 3 posts you would have 9 divs.

 

Any help greatly appreciated.

Um you are vastly over complicating the process why don't you take a look at mysql and about creating dynamic content. For example you can create as many pages as you like and view them using 1 file like this index.php?pageId = 4 where it says pageId = 4 that would be viewing page 4

First, you should use <textarea></textarea>. By not using the closing tag it could contribute to the problem (but probably isn't).

When you use the "w" command in PHP with fopen() you are telling PHP to make a new page every time.

 

$dateposted.html is referring to the variable called $dateposted, which is going to change from day to day.

 

To solve all of this, use one file name such as "posts.html" - don't use a changing variable in the file name,

And I would conjugate all the information together before writing to the file.

Then, when it's time to write to the file, you'll want to append the data using the "a" action. This will not over write the file ever time someone posts something.

 

<html>
 <head>
 </head>
 <body>
   <form name="form1" method="post" action="save.php?saving=1">
  <textarea id="date" name="date" cols="10" rows="1"></textarea>
  <textarea id="author" name="author" cols="10" rows="1"></textarea>
  <textarea id="post" name="post" cols="60" rows="1"></textarea>
  <input type="submit" value="Save">
   </form>
 </body>
</html>

And then for the PHP I'd use something like:

<?php
 $file = "posts.html"; // no variable in the value, it won't change.
 if(!file_exists($file)) {
   // use blank fopen($file, "w") to create the file
 }
 $date = "<div>".$_POST['date']."</div>";

 $author = "<div>".$_POST['author']."</div>";
 $post = "<div>".$_POST['post']."</div>";
 $conjugatedString = $date . $author . $post;
 // now we know the file exits for sure, we can append data to it
 $fp = fopen($file, "a") or die("Error");
 fwrite($fp, $conjugatedString);
 fclose($fp);
 echo "Saved $author's post in $file";
?>

 

Try that out, let me know if that works for you.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.