mysqli_query() expects at least 2 parameters

pathfinder

Member
Joined
Oct 3, 2012
Messages
58
Points
8
When I run this command mysqli_query it is given results in the error below

Code:
mysqli_query("INSERT INTO `username`.`email` (`userinfo`) VALUES ('".$email."')");
"Warning: mysqli_query() expects at least 2 parameters, 1 given in"

Why am I getting this error above? what does it mean and how to fix it?
 

energizedit

New member
Joined
Jan 1, 2017
Messages
9
Points
1
You may need to declare the table again with your variables like

Code:
mysqli_query("INSERT INTO `username`.`email` (`username`.`userinfo`) VALUES ('".$email."')");
I would say the problem has something to do with your table selection `username`.`email` that just doesn't look right.
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,487
Points
113
You are not telling it what mysql connection to use.

$con=mysqli_connect("localhost","my_user","my_password","my_db");
mysqli_query($con, "INSERT INTO Persons (FirstName,LastName,Age) VALUES ('Glenn','Quagmire',33)");
 

Steve32

Active member
Joined
Mar 15, 2014
Messages
210
Points
28
Steve32
Does this affect to the query of The OP asking?

If we use a normal MySQL connection like

Code:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
or open a Connection with MySQLi

Code:
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = mysqli_connect($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
then this command

Code:
mysqli_query("INSERT INTO `username`.`email` (`userinfo`) VALUES ('".$email."')");
could have errors or didn't work?
 

Rob Whisonant

Moderator
Joined
May 24, 2016
Messages
2,487
Points
113
Rob Whisonant
Since it is not being connected to any mysql connection it will never work. You have to tell it what database to query.

Also it is looking for a table named usernameemail as it is written. It is then looking for a field named userinfo to insert the value of $email.

Also, never try to mix mysql and mysqli syntax. They are not compatible.
 
Older threads
Newer threads
Replies
9
Views
8,403
Replies
4
Views
14,633
Replies
8
Views
6,693
Replies
1
Views
5,055
Recommended threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top