php - can't get the result of a query to output. (if there is an output)
<p>The program takes a variable $ask from a user which is a category of an interest such as sport, movies etc. then checks the database if that category exists, if it doesn't exist it adds it to the database. database memory, table - 'interestcategories' which at the moment just has 3 columns IID, Category and Comment. Adding to the database works however if it is in the database, printing out what is in there doesn't work.... </p>

<p>The problem mostly lies in these lines:</p>

<pre><code>   while ($row = mysqli_fetch_assoc($result)) {
    printf ("%s (%s)\n", $row["Category"], $row["Comment"]);
   }
   /* free result set */
   mysqli_free_result($result);
</code></pre>

<p>As nothing gets put to screen not even an error msg. 
There should only ever be printed one line, as the category only appears once in the table. 
Any ideas? </p>

<pre><code>  &lt;?php
  error_reporting(E_ALL);
  $link = mysqli_connect("localhost", "root", "", "memory");
  /* check connection */
  if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit();
  }

function notAnInterest($ask, $link)
{
$query2 = "INSERT into interestcategories (Category, Comment)
        VALUES ('$ask', 'Added by user') ";

$result2 = mysqli_query($link, $query2);
echo "&lt;pre&gt;Debug: $query2&lt;/pre&gt;\n";
if ( false===$result2 ) {
  printf("error: %s\n", mysqli_error($link)); 
  }
 echo 'added ' . $ask; 
 }

 if(isset($_POST['ask']) === true &amp;&amp; empty($_POST['ask']) === false) {
 $ask = trim($_POST['ask']);
$query = "
SELECT  *
FROM    `interestcategories`
WHERE `interestcategories`.`Category` = '$ask' ";

if ($result = mysqli_query($link, $query)) {
if(($row = mysqli_fetch_assoc($result)) === null) {
notAnInterest($ask, $link);
}
 /* fetch associative array */
    printf('here1');
 while ($row = mysqli_fetch_assoc($result)) {
    printf('here2');
  //printf ("%s (%s)\n", $row["Category"], $row["Comment"]);
}

 /* free result set */
 mysqli_free_result($result);
}

}

 /* close connection */
  mysqli_close($link);

  ?&gt;
</code></pre>
