1

I have a line of code in my php that reads:

 $sel_venue = "SELECT 'char_type' FROM 'character_type_allowed' WHERE     status='Open'";
 $run_venue = mysqli_query($con,$sel_venue);
 while ($row = mysqli_fetch_array($run_venue)) 

  if ($row['char_type'] == 'Mortal')
      { print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>"); }

The link associated with this does nothing. Zero interaction beyond acting likeit wants to expand. My error log produces this: Why is it asking for this?

[08-Aug-2016 23:28:41 America/New_York] PHP Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /home/houchat/public_html/incl/creation.php on line 8

2 Answers2

0

You can't use ' as ticks for field/tablenames.

Your query is producing an error. You can see the error with mysqli_error($con).

Please see the corrected code below

 $sel_venue = "SELECT `char_type` FROM `character_type_allowed` WHERE     status='Open'";
 $run_venue = mysqli_query($con,$sel_venue) or die(mysqli_error($con));
 while ($row = mysqli_fetch_array($run_venue)) {

   if ($row['char_type'] === 'Mortal') { 
      print ("<li><a href='http://houston-by-night.com/sheets/create/mortal.php'>Create Mortal</a></li>");
   }

 }
xyz
  • 559
  • 2
  • 11
-1

Your query failed, so $run_venue is the boolean false instead of what you expect. You should check for errors before you use any query result. Do this:

$run_venue = mysqli_query(...);

if(!$run_venue) die(mysqli_error($con));
... //<- we get here if the query succeeded

You will see the error. The problem is that your SQL statement wraps the table name between single quotes 'character_type_allowed', instead of backticks (backtick is above the tab key on my keyboard)

BeetleJuice
  • 39,516
  • 19
  • 105
  • 165