-2

I need to insert data into the database, but the error. Can someone help me? .............

CONEXAO.PHP

$banco = "*****";
$usuario = "*****";
$senha = "*****";
$hostname = "*****";

$conn = mysql_connect($hostname,$usuario,$senha); mysql_select_db($banco) or die( "Não foi possível conectar ao banco MySQL");

if (!$conn) {echo "Não foi possível conectar ao banco MySQL.
"; exit;}
else {echo "Parabéns!! A conexão ao banco de dados ocorreu normalmente!.
";}
mysql_close(); 

......................

CADASTRADO.PHP

include "conexao.php";
$consulta = "SELECT * FROM servicos";
$con = $conn ->query($consulta) or die ($conn->error); (((error in this line)))

...............

MSG ERROR

Parabéns!! A conexão ao banco de dados ocorreu normalmente!. (CONECTION OK)

Fatal error: Call to a member function query() on resource in /var/www/html/paranalocal.com.br/web/servicos.php on line 4
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • 3
    You should probably remove that password... – Ian Jun 07 '17 at 13:55
  • 1
    You're mixing `mysqli_` with `mysql_`. [The latter has been removed from PHP](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Machavity Jun 07 '17 at 13:55
  • 2
    `mysql_*` functions don't work like that. They're also outdated. Switch your code to use [PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php) or [mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead. – aynber Jun 07 '17 at 13:56
  • Not to mention you close the connection as soon as you open it – Qirel Jun 07 '17 at 13:58
  • 1
    I've edited out the user/pass but you still need to change it **immediately**. – Alex Howansky Jun 07 '17 at 14:01

1 Answers1

0

To use mysqli functions you need to create a connection to the database using mysqli.

Replace mysql_connect with the following:

$conn = new mysqli($hostname , $usuario, $senha, $banco);
Jerodev
  • 32,252
  • 11
  • 87
  • 108