Create blog from scratch without using wordpress [closed]

2

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

    
asked by anonymous 04.10.2017 / 06:25

1 answer

5

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

First 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 db_blog, in it you will create a table that we can call a blog with columns id, ip, name, email.

It will 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 bank and this table.

Having a form and a bank to store the information entered in the form, only the website recognizes that it has to take this information and store it in the database.

For this, we can make 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>';

?>

Done, now this page will pick up the information entered in the form and will store it in the database.

But how?

Simple, remember that you put in the text boxes there from your blog.html page a thing called name? We took this name and stored it inside a variable via post, that is, we stored what was typed in the box inside that variable of the update.php page.

Then we inform you which database we are using and connect to it, and then store the contents of those variables in the database.

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

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

It's simple, is not it? I hope I have helped!

    
04.10.2017 / 15:25