Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: mysqli_query() expects at least 2 parameters, 1 given. What? [duplicate]

Tags:

php

mysqli

I made a PHP page that is supposed to select two names from a database and displays them.

It just says:

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/tdoylex1/public_html/dorkhub/index.php on line 4

Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/tdoylex1/public_html/dorkhub/index.php on line 8

My code is:

<?php mysqli_connect(localhost,tdoylex1_dork,dorkk,tdoylex1_dork);
$name1 = mysqli_query("SELECT name1 FROM users
ORDER BY RAND()
LIMIT 1");

$name2 = mysqli_query("SELECT name FROM users
ORDER BY RAND()
LIMIT 1");

?>

<title>DorkHub. The online name-rating website.</title>
<link rel="stylesheet" type="text/css" href="style.css">
<body bgcolor='EAEAEA'>
<center>
<div id='TITLE'>
    <h2>DorkHub. The online name-rating website.</h2>
</div>
    <p>
    <br>
    <h3><?php echo $name1; ?></h3><h4> against </h4><h3><?php echo $name1; ?></h3>
    <br><br>
    <h2 style='font-family:Arial, Helvetica, sans-serif;'>Who's sounds the dorkiest?</h2>
    <br><br>
    <div id='vote'>
    <h3 id='done' style='margin-right: 10px'>VOTE FOR FIRST</h3><h3 id='done'>VOTE FOR LAST</h3>
like image 233
user2840637 Avatar asked Oct 02 '13 23:10

user2840637


People also ask

How many parameters does the mysqli_query () function accept?

PHP uses mysqli query() or mysql_query() function to create or delete a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.

How many parameter mysqli_query () Atleast it takes?

Warning: mysqli_query() expects at least 2 parameters, 1 given.

What does the mysqli_query () function do?

The query() / mysqli_query() function performs a query against a database.

What is the result of mysqli_query?

For successful queries which produce a result set, such as SELECT, SHOW, DESCRIBE or EXPLAIN , mysqli_query() will return a mysqli_result object. For other successful queries, mysqli_query() will return true .


1 Answers

the mysqli_queryexcepts 2 parameters , first variable is mysqli_connectequivalent variable , second one is the query you have provided

$name1 = mysqli_connect(localhost,tdoylex1_dork,dorkk,tdoylex1_dork);

$name2 = mysqli_query($name1,"SELECT name FROM users ORDER BY RAND() LIMIT 1");
like image 57
Shanaka WickramaArachchi Avatar answered Oct 14 '22 03:10

Shanaka WickramaArachchi