MySQLi does not execute insert within a function

3

I have this function:

function envia($mensgem) {
    $odb = mysqli_connect(HOST, USER, PASS, DATABASE);
    mysqli_query($odb, "INSERT INTO pedidos VALUES ('$mensagem')");
    mysqli_close($odb);
}

I use this function on another page calling it by require('funcoes/envia.php'); , I execute this function using envia('Olá mundo'); , I will see in phpMyAdmin and nothing has been registered.

I would like the insert to execute within functions to facilitate:)

PS: HOST, USER, PASS and DATABASE have been set correctly

    
asked by anonymous 19.11.2016 / 06:13

2 answers

8

But you are not specifying the column of the message, so what column of the pedidos table will this text ( $mensagem )? You should specify:

mysqli_query($odb, "INSERT INTO pedidos (<NOME DA COLUNA AQUI>) VALUES ('$mensagem')");

link

And you should use prepared statements , link

    
19.11.2016 / 10:41
-3

Use Mysql_execute ($ SeuInsert) and at the end mysql_close (YourConnection);

    
19.11.2016 / 14:19