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

1

Hello,

I can not execute this query, I have echoed this variable and all the data is being passed, but it does not enter my DB. When I copy the command and paste inside the phpMyAdmin query it works. Could someone give a help? Thanks! :)

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

mysql_query($link,$sql); 
    
asked by anonymous 11.06.2018 / 20:27

2 answers

3

You are using the mysql_query command in the wrong way.

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

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

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

It is suggested to change the mysql functions, which are obsolete, by mysqli

See more in the PHP documentation itself: Improved MySQL Extension

    
11.06.2018 / 20:35
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);'
    
11.06.2018 / 20:45