Can't solve the problem of Warning: mysql_fetch_assoc () expects parameter 1

<?php if(isset($_POST['done'])){ $mysqli=new mysqli('localhost', 'root', '', 'login'); $mysqli->query("SET NAMES TO `utf8`"); $query=mysql_fetch_assoc($mysqli->query("SELECT * FROM `users` WHERE `login`='".$_POST['login']."' AND `password`='".$_POST['password']."'")); if($query){ echo "Пользователь найден"; } else{ echo "Пользователь не найден"; } } ?> <h1>Log in</h1> <form action="" method="post"> <label>login</label> <br> <input type="text" name="login"/> <hr> <label>password</label> <br> <input type="password" name="password"/> <hr> <input type="submit" name="done" value="done"/> </form> 

Reported as a duplicate by members of Visman , Vanya Avchyan , Dmitriy Simushev , Alexey Shimansky , Mike Jun 14 '17 at 20:21 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • And how does the question sound? - 0xdb
  • @ 0xdb it doesn’t matter - Aleksey Shimansky

1 answer 1

Example from php manual ( fixed for your situation ):

 if(isset($_POST['done'])){ $mysqli=new mysqli('localhost', 'root', '', 'login'); $mysqli->query("SET NAMES TO `utf8`"); $result = $mysqli->query("SELECT * FROM `users` WHERE `login`='".$_POST['login']."' AND `password`='".$_POST['password']."'")); if (!$result) { echo "Could not successfully run query from DB"; exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } $query = mysql_fetch_assoc($result); if ($query) { echo "Пользователь найден"; } else { echo "Пользователь не найден"; } } 

You need to make sure that you get the desired result from the database, only then use the function mysql_fetch_assoc (resource $ result)