Create blog from scratch without using wordpress

Asked

Viewed 422 times

2

I need to create a blog without using Wordpres or any other ready-made structure, which language I can use and which is the fastest way to do it, the blog has a form that will save the e-mail, nome completo and ip da pessoa, I already have the html and css part ready I need to create the database and the part that makes the integration with everything else.

  • There is no magic formula that a person can follow, except when we choose to use "ready-made structures", of course we already have the table practically done. But if you want to do something like a blog without that kind of help, you’ll need to use a lot of PHP to make the links between the database and your site

  • If I’m not mistaken, the DOO Framework has - or had - a simple blog example, maybe something in the FW serves as a basis for you.

  • Use your html and css that have already been made, create Javascript commands to call via Ajax your API.

1 answer

5

To get your form working, you will need some items:

First of all the page that will contain the text boxes that will receive the information, ie the page.html:

    <html>
        <head> 
            <title> Formulário </title>
        <head>
        <body>
            <div class="container">
    
            <div class="row">
                <div class="col-lg-12 text-center">
                    <h1 style="
                        margin-top:100px;"> Formulário </h1>
                    <p> </p>
                    <p class="lead"></p>
                    <ul class="list-unstyled">
                        <form id="cadastro" name="cadastro" method="post" action="update.php">
                            <div class="col-lg-12">
                                <div class="form-group" style="
                            text-align: left;
                            margin-top:50px;">
                                    <label  for="ip">ip: </label>
                                    <input  type="text" required class="form-control" id="identifiant" placeholder="Ip da pessoa" name="ip">
                                 </div>
                            </div>
                            <div class="col-lg-12">
                                <div class="form-group" style="
                            text-align: left;">
                                    <label  for="nome">Nome: </label>
                                    <input  type="text" required class="form-control" id="nome" placeholder="Nome da pessoa" name="nome">
                                 </div>
                            </div>
                            <div class="col-lg-12">
                                <div class="form-group" style="
                            text-align: left;">
                                    <label  for="email">E-mail: </label>
                                    <input  type="text" required class="form-control" id="email" placeholder="Email da pessoa" name="email">
                                 </div>
                            </div>
                                    <button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
                                </div>
                            </div>
                         </form>
                    </ul>
                </div>
            </div>
        </div>
    </body>
</html>

Having the form, you need to have a database with a table to store this information.

You will need to create a database, we can give it the name of db_blog, in it you will create a table that we can call blog with the columns id, ip, name, email.

It’ll look something like this:

id  |  ip  |  nome  |  email
1     123    Mariana  [email protected]
2     456    Pedro    [email protected]

You can install phpMyAdmin to create this database and table.

Having a form and a database to store the information entered in the form, all that remains is for the site to recognize that it has to take this information and store it in the database.

For this, we can do an update.php page:

<?php

    $ip                   = $_POST['ip'];
    $nome                 = $_POST['nome'];
    $email                = $_POST['email'];

    $strcon = mysqli_connect('localhost','root','', 'db_blog') or die('Erro ao conectar ao banco de dados');
    $sql = "INSERT INTO blog VALUES ('$id', '$ip', '$nome', '$email')"; 
    mysqli_query($strcon,$sql) or die("Erro ao tentar cadastrar registro");
    mysqli_close($strcon);

    echo '<script type="text/javascript">
            alert("Salvo com Sucesso !");
            window.history.go(-1);
        </script>';

?>

Ready, now this page will take the information entered in the form and will store in the database.

But how?

Simple, remember you put in the text boxes there on your blog.html page something called name? We take this name and store it within a variable through post, that is, we store what was typed in the box inside this variable of the update.php page.

Then we inform which database we are using and make connection with it to, soon after, store the contents of these variables in the database.

Finally, we made a little script to warn the user that what he typed in the form was saved successfully.

The blog.html and update.php pages are linked through an action there in the form tag of the html page that redirects to this update page as soon as the user clicks on save, and this page saves.

It’s simple, isn’t it? I hope I’ve helped!

  • If that answer solved your problem, don’t forget to mark the right one down there. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.