Warning: mysqli_real_escape_string() expects Exactly 2 Parameters, 1 Given

Asked

Viewed 201 times

0

I’m making a posting system using PHP and Mysqli, but there are some errors that I’m not able to fix.inserir a descrição da imagem aqui

Follow the PHP code below:

<?php
 if (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>
  • Procedural style string mysqli_real_escape_string ( mysqli $link , string $escapestr )

1 answer

0

Missing to pass the connection object by parameter, for example:

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

$city = "'s Hertogenbosch";

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

Or in object-oriented style:

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

$city = "'s Hertogenbosch";

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

Examples and complete explanations on documentation

Browser other questions tagged

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