drmg17928 2014-06-25 18:55
浏览 54
已采纳

使用php存储提交信息并显示在单独的html页面上

I am trying to create a news page for a pharma website.

I have created a news article "creation" page that allows a user to input information such as author, description, and body.

The code looks like this.

<html>
<body>
<style>
    textarea 
    {
        resize: none;
    }
</style>

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

   <label for="textarea">Title:</label>
   <p></p>
   <textarea rows="1" cols="100" name="title"></textarea>
   <br></br>
   <label for="textarea">Author:</label>
   <p></p>
   <textarea rows="1" cols="100" name="author"></textarea>
   <br></br>
   <label for="textarea">Description:</label>
   <p></p>
   <textarea rows="15" cols="100" name="desc"></textarea>
   <br></br>
   <label for="textarea">Body:</label>
   <p></p>
   <textarea rows="15" cols="100" name="body"></textarea>
   <br></br>

   <p><input type="submit" name="submit" value="Submit" /></p>

</form>
</body>
</html>

That information gets sent to foo.php, and I would like foo.php to dynamically create a div with the title, author, publish date, and description displayed within. This div would then have a "Read More" button that would display the actual article or "body" in this case.

I would then like to insert this div into a seperate html page. So in other words, every time the user creating a new article clicks the submit button, the information is processed, added to a div element and then that div is inserted into another html page.

Is there any way to do this, or some sample news/articles tutorial that explains how to do this? I've been searching for hours and there seems to be nothing on this particular topic. I've also tried something along the lines of this, but this has gotten me nowhere, and after 3+ days of trying to figure this out, Im ready to gouge my eyes out.

<script>
<?php
foreach (glob("*.txt") as $filename)
{
    $lines_array = file($filename);

    $search_string_title = "Article_title";
    $search_string_published = "Published";
    $search_string_author = "Author";
    $search_string_desc = "Description";
    $search_string_body = "Body";

    foreach($lines_array as $line)
    {
        if(strpos($line, $search_string_title) !== false)
        {
            list(,$title_str) = explode(":", $line);
        }
        if(strpos($line, $search_string_published) !== false)
        {
            list(,$published_str) = explode(":", $line);
        }
        if(strpos($line, $search_string_author) !== false)
        {
            list(,$author_str) = explode(":", $line);
        }
        if(strpos($line, $search_string_desc) !== false)
        {
            list(,$desc_str) = explode(":", $line);
        }
        if(strpos($line, $search_string_body) !== false)
        {
            list(,$body_str) = explode(":", $line);
        }
    }

    $article_title = $title_str;
    $published = $published_str;
    $author = $author_str;
    $desc = $desc_str;
    $body = $body_str;

    $news_content= array($article_title, $published, $author, $desc, $body);

}
?>

var news = <?php echo json_encode($news_content) ?>;
var title = news[0];
var published = news[1];
var author = news[2];
var desc = news[3];
var body = news[4];

var div = document.createElement("div");
div.style.width = "600px";
div.style.height = "600px";
div.style.background = "red";
div.style.color = "white";

var sHTML = '<div style="text-align:center; padding:15px; font-weight:bold;">' + title + "<br />" + "<br />" + "Published: " + published + "<br />" + "Author: " + author + "<br />" + "<br />" + desc + </div>';

div.innerHTML = sHTML;

div1.appendChild(div);

</script>
  • 写回答

3条回答 默认 最新

  • dongpao1083 2014-06-25 19:03
    关注

    What you are trying to do sounds a lot like MVC

    The way I would do it is make a page like the one you're describing and when I'm done entering the info, I'd send the data to a PHP script to put my information in a database(like MySQL).

    On the page where you want the divs to appear I'd then just loop through my database articles rows and make my php echo the info you want in those divs.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错