Mysqli does not run Insert within a function

Asked

Viewed 124 times

3

I have that 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 her by require('funcoes/envia.php');, run this function using envia('Olá mundo');, I will check on phpMyAdmin and nothing has been registered.

I would like Insert to perform within functions to facilitate :)

PS: The HOST, USER, PASS and DATABASE were correctly defined

2 answers

8


  • Whoa, thanks! I didn’t think I needed to inform the names of the columns :)

  • You’re welcome @Gustavodias

-3

Use Mysql_execute($Seuinsert) and at the end use mysql_close(Your connection);

  • Alvaro, mysqli_execute is used with mysqli_prepare, and it is using mysqli_query. Also, it is not mysql_, it is mysqli_. mysql_ functions are obsolete. It’s nice your initiative to help, but it’s important to pay attention to these details so that the next posts have a better score.

Browser other questions tagged

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