Jump to content

post and write onto a page


PlagueInfected

Recommended Posts

I'm trying to make an admin panel and the thing I want to do is my admins to post updates to be displayed onto the site.

 

I made the form for it as well as the script

 

here is the full code.

 

<fieldset>

<legend>Updates</legend>

  <form action="update_page.php" method="post">

 

  Administrator Name: <input type="text" name="name" />

  Subject: <input type="text" name="subject" />

  Text: <input type="text" name="mainsubject" />

 

  <input type="submit" value="submit" />

  <input type="reset" value="reset" />

 

  </form>

 

</fieldset>

 

here is the php script

 

<?php

 

//update_page.php

/*

$name = $_POST['name'];

$subject = $_POST['subject'];

$mainsubject = $_POST['mainsubject'];

*/

//using variables to attempt an array

 

$myFile = "inc/updates.php";

$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = "<div class=\"name\">" . $_POST['name'] . "</div>";

fwrite($fh, $stringData);

$stringData = "<div class=\"subject\">" . $_POST['subject'] . "</div>";

fwrite($fh, $stringData);

$stringData = "<div class=\"mainsubject\">" . $_POST['mainsubject'] . "</div>";

fclose($fh);

 

?>

Link to comment
https://forums.phpfreaks.com/topic/169098-post-and-write-onto-a-page/
Share on other sites

try:



<?php

//update_page.php

$name = $_POST['name'];
$subject = $_POST['subject'];
$mainsubject = $_POST['mainsubject'];

//using variables to attempt an array

$myFile = "inc/updates.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "<div class=\"name\">" . $_POST['name'] . "</div>";
fwrite($fh, $stringData);
$stringData = "<div class=\"subject\">" . $_POST['subject'] . "</div>";
fwrite($fh, $stringData);
$stringData = "<div class=\"mainsubject\">" . $_POST['mainsubject'] . "</div>";
//checking if data is written to file if true ech success
if (fwrite($fh, $stringData) === FALSE) {
        echo "Cannot write to file ($myFile)";
        exit;
    }
    echo "Success, wrote ($stringData) to file ($myFile)";
fclose($fh);

?>

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.