"mysqli_query() expects parameter 1 to be mysqli" warning

Hello to everyone.

I need some help here. I am trying to set up the comments section for my website. Something goes wrong. Supposedly because of the wrong syntaxis. Anyway, here’s is what I’ve got:


$servername = "localhost";
$username = "user";
$password = "12345";
$database = "db";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());

echo "Connected successfully";

ok, so at this point everything is ok, and code returns “Connected successfully”


<?php include("connect.php");

// **********************************************
if($_POST['message'] != '' && $_POST['author'] != ''){

$author = $_POST['author'];
$author = addslashes($author);
$author = htmlspecialchars($author);
$author = stripslashes($author);
$author = ($author);

$message = $_POST['message'];
$message = addslashes($message);
$message = htmlspecialchars($message);
$message = stripslashes($message);
$message = ($message);

$date = date("d-m-Y в H:i:s");
$result = ("INSERT INTO messages (author, message, date) VALUES ('$author', '$message', '$date')");
if($result == true){
echo 0; //success
echo 1; //message was not sent. DB error
echo 2; //no blank messages


and this part is in the index.html file:

<div id="commentBlock">
   $result = mysqli_query($database,"SELECT * FROM messages");
   $comment = mysqli_fetch_array($result);
	   echo "<div class='comment'>Автор: <strong>".$comment['author']."</strong>
while($comment = mysqli_fetch_array($result));

<form action="sendMessage.php" method="post" name="form">
 <input name="author" type="text" id="author"></p>
 <p>Текст сообщения:
<textarea name="message" rows="5" cols="50" id="message"></textarea></p>
 <input name="js" type="hidden" value="no" id="js">
 <p><input name="button" type="submit" value="Отправить" id="send"> <span id="resp"></span></p>

as a result:

  1. Warning : mysqli_query() expects parameter 1 to be mysqli, string given in  /storage/ssd1/186/10282186/public_html/index.html  on line  23

2.  Warning : mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in  /storage/ssd1/186/10282186/public_html/index.html  on line  24

3.  Warning : mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in  /storage/ssd1/186/10282186/public_html/index.html  on line  28

line 23 $result = mysqli_query($database,“SELECT * FROM messages”);

line 24 $comment = mysqli_fetch_array($result);

line 28 while($comment = mysqli_fetch_array($result));

Would be really grateful if somebody can help me out :slight_smile:

forgot to say that data is not saved to database