Database does not display data entered by the user

1

Good morning, I'm trying to make a news system, but the database does not receive php data. I would like to know how to resolve this.

<html>
<head>
    <meta charset="utf-8">
    <title>Inserir Notícia</title>    
</head>

<body>
    <?php

        $host = "localhost";
        $user = "root";
        $pass = "";
        $banco = "sistemanoticias";
        $conexao = @mysql_connect($host, $user, $pass) or die(mysql_error()); 
        mysql_select_db($banco) or die (mysql_error());

    ?>

    <?php 

        $titulo = $_POST['titulo'];
        $campo = $_POST['campo'];

        $sql = mysql_query("INSERT INTO noticias(titulo, campo) VALUES('$titulo, $campo)"); 
        echo "Notícia inserida com sucesso";
    ?>

    <a href="inicio.html">Retornar para o Início</a>

</body>
</html>
    
asked by anonymous 06.09.2015 / 15:32

1 answer

3

The text fields must be enclosed in single quotes, always add mysql_error() to get the bank error message.

$titulo = mysql_real_escape_string($_POST['titulo']);
$campo = mysql_real_escape_string($_POST['campo']);
$sql = "INSERT INTO noticias(titulo, campo) VALUES('$titulo', '$campo')";
$result = mysql_query($sql) or die(mysql_error());

Recommended reading:

Why should not we use functions of type mysql_ *?

MySQL vs PDO - Which is the most recommended to use?

Why do you say that using @ atm to suppress errors is bad practice?

    
06.09.2015 / 17:42