Error while sending post request

Warning: mysqli_query () expects at least 2 parameters, 1 given in /home/u249644105/public_html/getUser.php on line 12

Warning: mysql_fetch_array () expects parameter 1 to be resource, given in /home/u249644105/public_html/getUser.php on line 14

Code itself

if($_SERVER['REQUEST_METHOD']=='POST'){ //Getting values $imei = $_POST['imei']; $sql = "SELECT * FROM user WHERE imei='$imei'"; require_once('dbConnect.php'); $result = mysqli_query($sql); $array = mysql_fetch_array($result); echo $array['username']; } 

When sending with a POST request, find it in the database and send a response in the form of the username associated with it

1 answer 1

Refer to the mysqli_query documentation, where it is indicated:

 mixed mysqli_query(mysqli $link, string $query [, int $resultmode = MYSQLI_STORE_RESULT ]) 

That is, the link to the variable with the connection is first indicated, and then the request.

I can not say for sure that you have the included file, so I will take from the example:

 $link = mysqli_connect("localhost", "my_user", "my_password", "world"); 

Then it will be necessary to write:

 $db_result = mysqli_query($link, $sql); // обратите внимание на $link! 

Actually, the second varning tells you about the same thing: I need the right data, not null (or what does it return in this case?).

  • $ result = mysqli_query ($ con, $ sql); - Pavel Ananiev
  • Vseravno: Warning: mysql_fetch_array () expects parameter 1 to be resource, object given in /home/u249644105/public_html/getUser.php on line 19 - Pavel Ananiev
  • Please show me what happened in pastebin.com for example. - higimo