Problem with mysql_query, the data does not fall in the SQL database.

Asked

Viewed 167 times

1

Hello,

I cannot run this query, I echo this variable and all data is being passed, but it does not enter my BD. When I copy the command and paste it into the phpMyAdmin query works. Could someone help? Thanks! :)

$sql = "INSERT INTO `tabela2` (`nome`, `cor`, `sexo`) VALUES 
('$nome','$cor','$sexo')";

mysql_query($link,$sql); 
  • 1

    have tried with mysqli ?

  • No, like I do?

  • 1

    mysql_query() this function has been removed from php7, its substitute is the mysqli_query.

  • But the version of php on the server is 5.6.30, I can use it anyway?

2 answers

3

You are using the command mysql_query wrongly.

According to the PHP documentation, the function mysql_query is defined by:

mysql_query ( string $query [, resource $link_identifier ] )

Where the query string should be the first parameter and not the second, as you are doing.


It is suggested to change the obsolete mysql functions to mysqli

See more in the PHP documentation itself: Improved Mysql extension

0

`$host = "localhost";
$user = "seu usuario";
$pass = "sua senha"
$db = "seu banco de dados";

$conn = mysqli_connect($host,$user,$pass,$db);`


`$sql = "INSERT INTO tabela2 (nome,cor,sexo) VALUES ('$nome','$cor','$sexo')";
$inseriu = mysqli_query($conn,$sql);`
  • the last line should not be $insert = mysqli_query($sql, $Conn); ?

  • 1

    no friend, first we pass the connection dps the insertion

Browser other questions tagged

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