0

I have this problem where I am trying to get input from the user and then display information. The user is meant to insert an ID number, obtained by $_POST[PID], then I catch that in result and when I try to get the result and print their info. This is the code:

 $result = mysqli_query($connection, $_POST[PID]);

 while($row = mysqli_fetch_array($result))
 {
    echo some info
    echo "<br>";
 }

However such code yields this error:

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given

How can I fix such error such that I am able to obtain the input and use it in mysqli_fetch_array

user1404664
  • 73
  • 1
  • 2
  • 8

3 Answers3

0

The second argument for mysqli_query() must be a query.

For instance:

$var = "insert into tbl where field = '{$_POST['PID']}'";
$result = mysqli_query($connect, $var);

Read it here: http://www.w3schools.com/php/func_mysqli_query.asp

witherwind
  • 472
  • 3
  • 15
0

Refer to my answer from your previous question(similar to this question)

Obtain resource from POST php

Community
  • 1
  • 1
remedy.
  • 2,032
  • 3
  • 25
  • 48
-1

Please learn about these functions to properly use them (Link here)

Instead of $_POST[PID] in mysqli_query() there must be some query string like

"select * from tablename where id ='". $_POST['PID']."'

Also, you need to enclose the key name within single quotes like $_POST['PID']

Boshi
  • 230
  • 1
  • 4
  • I tried this and it is giving me an error of unexpected string, am I supoused to substitute the "select * from tablename where id =" with something else? – user1404664 Feb 17 '14 at 04:57
  • That was an example. You need to customize that according to your database, table and fields. I strongly recommend you to spend some time learning the basics of sql and then you'll understand it properly. Visit the useful links posted by users here. – Boshi Feb 17 '14 at 05:01