Warning: mysqli_real_escape_string () expects exactly 2 parameters, 1 given

0

I'm doing a posting system using PHP and Mysqli, but there are some bugs that I can not fix.

Mycodesbelow..

PHP

<?phpif(isset($_POST['enviar'])){$autor=mysqli_real_escape_string(trim(strip_tags($_POST['autor'])));$titulo=mysqli_real_escape_string(trim(strip_tags($_POST['titulo'])));$texto=mysqli_real_escape_string(trim(strip_tags($_POST['texto'])));$sql=mysqli_query("INSERT INTO postagens (Titulo, Texto, Autor) VALUES ('$titulo', '$texto', '$autor')") or die(mysqli_error());

if ($sql){
    echo '<script>alert("Pergunta Enviada!");location.href=("");</script>';
}else{
    echo '<script>alert("Ocorreu um problema!");location.href=("");</script>';
}

}

?>

HTML

<form action="" method="POST" enctype="multipart/form-data">


        <label for="inputTitulo">Titulo</label>
        <input type="text" name="titulo" class="form-control" id="titulo"  required="" placeholder="titulo..">


    <label >Texto</label>
    <input type="text" name="texto" class="form-control"  required="" placeholder="escreva sua pergunta...">


    <label>Autor</label>
    <input type="text" name="autor" class="form-control"  required="" placeholder="Autor">



<button type="submit" name="enviar" id="enviar" class="btn btn-primary" 
value="Publicar">Publicar!</button>
</form>
    
asked by anonymous 24.07.2018 / 00:16

1 answer

0

The connection object is missing, for example:

$link = mysqli_connect("localhost", "my_user", "my_password", "dbname");

$city = "'s Hertogenbosch";

$city = mysqli_real_escape_string($link, $city);

Or in the object-oriented style:

$mysqli = new mysqli("localhost", "my_user", "my_password", "dbname");

$city = "'s Hertogenbosch";

$city = $mysqli->real_escape_string($city);

Examples and full explanations on documentation

    
24.07.2018 / 02:10