[php] Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\

I'm doing a tutorial in which the author has not updated his content to reflect changes in the PHP documentation. Anyways, I need to know what is parameter is being asked of me to provide. I've checked that all things are in order, but I literally don't know what I'm supposed to provide. Here's what I have:

Connects.php

<?php
$connect_error = 'Sorry, we\'re experiencing connection issues.';
$con = mysqli_connect('localhost', 'root', 'PwdSQL5');
mysqli_select_db('phpcadet') or die($connect_error);
?>

And yet I get the error: enter image description here

Edit: After figuring out to resovle the Connects.php issue, here's why I get when fixed it... more errors and here's my code. Remember I'm new to PHP and am following a poorly done tutorial.

Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, string given in C:\vhosts\phpcadet\core\functions\general.php on line 4

General.php

<?php
function sanitize($data)
{
return mysqli_real_escape_string($data, 'What goes here?');
}
?>

Then this: Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\vhosts\phpcadet\core\functions\users.php on line 7

Users.php

<?php
require 'core/database/connects.php';

function user_exists($username)
{
  $username = sanitize($username);
  $query = mysqli_query($_POST['username'], "SELECT * FROM users");
  $row = mysqli_fetch_array($query);

  if($row['username']==$username)
  {
     echo "Welcome, $username!";
     return true;   
  }
  else echo "Please enter a valid username and password";
  return false;
}   

function user_active($username)
{
  $username = sanitize($username);
  $query = mysqli_query($_POST['username'], "SELECT * FROM users");
  $row = mysqli_fetch_array($query);

  if($row['username']==$username && $row['active']==1)
  {
     echo "Welcome, $username!";
     return true;   
  } 
  else echo "Your username and password could not be verified.";
  return false;
  }
 ?>

And finally this: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\vhosts\phpcadet\core\functions\users.php on line 8

See same code above

Some of my code is a compilation of other answers to solve issues with the lesson, and were found on Stack. Due to inconsistecy of them, it makes it hard for me to pick up what is going on... Coming from a different language, I not that familiar here, and just need the help, so it all clicks. Then I'll have "understanding" of what the manual is saying. Thanks.

This question is related to php mysql mysqli

The answer is


mysqli_select_db() should have 2 parameters, the connection link and the database name -

mysqli_select_db($con, 'phpcadet') or die(mysqli_error($con));

Using mysqli_error in the die statement will tell you exactly what is wrong as opposed to a generic error message.


Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to mysqli

phpMyAdmin ERROR: mysqli_real_connect(): (HY000/1045): Access denied for user 'pma'@'localhost' (using password: NO) mysqli_real_connect(): (HY000/2002): No such file or directory mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it Call to a member function fetch_assoc() on boolean in <path> How can I enable the MySQLi extension in PHP 7? Fatal error: Call to a member function bind_param() on boolean Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\ How to check if a row exists in MySQL? (i.e. check if an email exists in MySQL) Object of class mysqli_result could not be converted to string in mysqli::query(): Couldn't fetch mysqli