0

Well, i'm very new to Javascript and PHP, and I have a problem.

The idea: I want to do some post area, where in a single PHP page people will fill a form and it will create a little bootstrap panel. Don't worry about multiple pages, it's like a... wall. Example:

<div class="col-sm-6">
<div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title">My message</h3>
  </div>
  <div class="panel-body">
  <h6>This is a test!</h6>
  </div>
  </div>
</div>

I don't know exactly how to do this. What i think is that in another page, there will be a form receiving the html contents for the panel title and body and then the PHP code will create html code [not a file] using this text and will put them in another file.

EDIT: As you can see in the comments, i'll have to use PHP and mySQL. I'm still not sure on how to do that.

18
  • Do you need to save the file ? or just open a new page and when user leave it, all gone ? Commented Jul 22, 2016 at 13:12
  • 1
    @A.Rossi Well, as i said, it is like a wall. The "posts" will keep in the place where they should be. And about the post page, it should remain there. Commented Jul 22, 2016 at 13:14
  • Someone tell me if i'm wrong, but i think you need a server side for this, with a databse to store all your posts Commented Jul 22, 2016 at 13:15
  • @A.Rossi Really? Can't you edit an external file or create a function with javascript/jQuery? Commented Jul 22, 2016 at 13:17
  • no, javascript doesn't allow to write in external file. You can create a file but not edit Commented Jul 22, 2016 at 13:18

1 Answer 1

1

Okay, i made this for you. The following is just for give you a start, the code is not correctly written, but it will give you a way to start your "project".

Firstly, create your database for storage your post, as follow :

TABLE_POST
title
content
date
autor

Then wall.php :

Start your file by getting with a query, all existing post in your database :

var post_list = "select id, pseudo, title, date, autor from table_post";

Once you have it, display it as you want :

<div>
foreach (post in post_list) {
echo "<div>";
echo "<h1>".post["title"]."</h1>";
echo "<p>".post["content"]."</p>";
      ...
echo "</div>";
}
</div>

In an other page, you can have your form : form.php

<form id='myform' method='post' action='add_post.php'>
<input type='text' id='title'/>
<input type='text id='content' />
<input type='text' id='autor' />
<input type='submit' value='Post it !'>
</form>

And in an other page, you can have the function to insert in the database :

add_post.php

insert into table_post VALUES ($_POST["title"], $_POST["content"], NOW(), $_POST["autor"]);

I repeat, i just give a structure for your achievement, i didn't provide a correct syntaxe of the code. Hope it can help you

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Well, a little too much, it's a lot simpler, no date or author, but that helps. Thank You!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.