Warning: mysqli_select_db() expects exactly 2 parameters, 1 given
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.
mysqli_select_db() expects exactly 2 parameters
do the correction as below:
$conn = mysqli_connect('localhost', 'root', '');
the first thing that you have to pass connection variable in the select_db as first parameter. as below.
mysqli_select_db($conn,'altislife-dev');
also you have to pass connection variable in mysqli_query() as first parameter as given below.
$records=mysqli_query($conn,$sql);
Warning: mysqli_select_db() expects exactly 2 parameters, 1 given *13*
The first parameter of mysqli_select_db()
is connection object. This is the syntax :
mysqli_select_db(connection,dbname);
Change your code to:
$con = mysqli_connect("$host", "$username", "$password")or die("cannot connect server ");
mysqli_select_db($con,$db_name)or die("cannot select DB");
Add the connection object as first parameter in mysqli_query
and mysqli_fetch_array
functions too. Please refer this link for the syntax.
mysqli_select_db() expects exactly 2 parameters, 1 given
Posting as a community wiki. I don't want rep from this and there shouldn't.
$connexionbase = mysqli_select_db($base)
Just as the error states. You need to pass the db connection as the first argument:
$connexionbase = mysqli_select_db($connexion, $base)
Reference:
- http://php.net/manual/en/mysqli.select-db.php
Example from the manual:
bool mysqli_select_db ( mysqli $link , string $dbname )
Sidenote:
return(($connexion && $connexionbase));
TBH, I've never seen this type of syntax for a return. Far as I know, you can return only once or using an array.
Pulled from this answer https://stackoverflow.com/a/3815243/1415724
You can only return one value. But you can use an array that itself contains the other two values:return array($uid, $sid);
Instead of going through all that trouble, just use the 4 parameters:
$connexion = mysqli_connect($server,$loginsql,$passsql, $base)
as per the manual:
- http://php.net/manual/en/function.mysqli-connect.php
then return with and if it's really needed.
return $connexion;
Plus, why are you intending to use MD5 to store passwords with? That hashing function is no longer considered safe to use.
You're better off using password_hash()
.
- http://php.net/manual/en/function.password-hash.php
This is the 21st century after all.
and $HTTP_COOKIE_VARS
, that's deprecated.
- http://php.net/manual/en/reserved.variables.cookies.php
I've no idea why you're using that code or where you got it from.
PHP session variables not carrying over to my logged in page, but session ID is
I don't see a session_start()
in your login script. If you aren't starting the session I don't think php will save any data you place in the $_SESSION
array. Also to be safe I'd explicitly place variables into the $_SESSION
array instead of just overwriting the whole thing with $_SESSION = mysql_fetch_array($result);
.
Related Topics
Get Specific Columns Using "With()" Function in Laravel Eloquent
How to Perform Static Code Analysis in PHP
Download File Through an Ajax Call PHP
Login to Remote Site With PHP Curl
PHP Reading Shell_Exec Live Output
How to Run a .Bat File from PHP
PHP.Ini & Smtp= - How to Pass Username & Password
Check File Extension in Upload Form in PHP
How to Make Pdf File Downloadable in HTML Link
How to Execute Two MySQL Queries as One in PHP/MySQL
How to Refresh Token With Google API Client
Json_Encode PHP Array as Json Array Not Json Object
Convert Command Line Curl to PHP Curl