Change page information with PHP

Asked

Viewed 576 times

0

I am doing a College job and in it I need to change page information like title-intro, blockquote and the cite from the page below, but it has to be done through another page as if it were an administrative page the only idea I had was through form and using the POST method, but it doesn’t seem to be the right way, as I can do it in a correct and simple way?

Filing cabinet adm.php.

<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <title></title>
</head>

<body>

    <form method="post" action="index.php">
       <input type="text" name="titulo" placeholder="Digite o novo título">
        <input type="submit" value="Alterar">
    </form>
</body>
</html>

My index file I need to change index.php

<?php

    $titulo = $_POST["titulo"];

?>


<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8">
    <title>Site com PHP</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <section class="intro">
        <div class="container">
            <h1 class="titulo-intro"><?php echo $titulo ?></h1>
            <blockquote class="quote">"não tenha nada em sua casa que você não considere útil ou acredita ser bonito"</blockquote>
            <cite>Willian Morris</cite>
        </div>
    </section>
</body>
</html>

And the CSS

body {
    background: #444;
}
.intro {
    color: #FFF;
    background: url(../img/bg.jpg);
    height: 380px;
    text-align: center;
}
.titulo-intro {
    font-size: 48px;
    font-weight: bold;
    text-transform: uppercase;
    margin-top: 60px;
}
.quote {
    width: 32%;
    margin: 0 auto;
    font-size: 14px;
    font-style: italic;
}

.quote::before, .quote::after {
    content: "";
    display: block;
    height: 3px;
    width: 60px;
    background: #FFF;
    margin: 10px auto;
}
  • Your question seems to me to be quite broad. The idea is you save this data in the database. Hence, through a parameter $_GET, you get the id of what was saved in the table and brings the results to the page.

  • "but it doesn’t seem to be the right way, "why?

  • I think a good place to start is How to write values to Mysql database with PHP

  • It makes no sense to do what you are doing through the POST. You want the admin to publish something, and it reflects in the PHP script, like a template, which contains the same styles, but only varies the data. I think I’d need at least a dB there.

  • @Wallacemaxters thanks for the answer, I also see no other alternative to not know use a simple dB here. Thanks even, the link helped me a lot.

1 answer

-1


The correct way, at first glance, would be with AJAX requests. You would have a font a JS making requests to this other page in PHP, capturing the values and updating them.

function ajax() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "OUTRA-PAGINA.PHP", true);
  xhttp.send();
}

Browser other questions tagged

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