mysqli_query() expects Exactly 2 Parameters 1 Given

Asked

Viewed 175 times

0

Someone help me with these 2 mistakes?

Warning: mysqli_select_db() expects Exactly 2 Parameters, 1 Given in C: xampp htdocs Flexor config.php on line 11


Fatal error: Uncaught Error: Call to Undefined Function mysql_error() in C: xampp htdocs Flexor config.php:11 Stack trace: #0 C: xampp htdocs Flexor logar.php(2): include() #1 {main} thrown in C: xampp htdocs Flexor config.php on line 11

<?php
$host = "localhost"; //Servidor do mysql
$user = "root"; //Usuario do banco de dados
$senha = ""; //senha do banco de dados
$db = "jpec"; //banco de dados
$nome_site = "nome"; //Nome do site
$email = "[email protected]"; //E-mail do administrador
$site = "http://www.jpecinformatica.com"; //Seu site n se esuqece de bota o http://

mysqli_connect($host, $user, $senha) or die (mysql_error());
mysqli_select_db($db) or die (mysql_error());
?>

1 answer

1

As the error itself says, mysqli_select_db expects two parameters, but only received 1. According to the documentation, the mysqli_select_db should receive a link, which is generated by the functions mysqli_connect or mysqli_init, that is to say:

$link = mysqli_connect($host, $user, $senha);
mysqli_select_db($link, $db);

About the error Call to undefined function mysql_error, again, according to the documentation this function has been discontinued, use mysqli_error as indicated here. To handle errors during the mysqli_connect, utilize mysqli_connect_error:

$link = mysqli_connect($host, $user, $senha) or die(mysqli_connect_error());
mysqli_select_db($link, $db) or die(mysqli_error($link));

Browser other questions tagged

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