我在php中编写一个madlib,使用mysql将其保存到db,然后尝试按降序排出每个新故事

I am not sure how to get the story out of the db, I am getting this error:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in /home/ubuntu/workspace/projects/project_1/madlib.php on line 33 Call Stack: 0.0009 248160 1. {main}() /home/ubuntu/workspace/projects/project_1/madlib.php:0 0.0058 257240 2. mysqli_fetch_array() /home/ubuntu/workspace/projects/project_1/madlib.php:33

<?php
//connecting to the db
$dbc = mysqli_connect('localhost', 'root', '', 'project1')
        or die('Error connecting to MySQL server.');

//creating variables       
$noun = $_POST['noun']; 
$verb = $_POST['verb'];
$adjective = $_POST['adjective'];
$body_part = $_POST['bodypart'];
$food_item = $_POST['fooditem'];
$full_story = "Here are some things to do at recess." 
              "Start a game of touch $body_part-ball." 
              "Put a $noun in someones lunch." 
              "Start a $food_item fight in the school $adjective room." 
              "Choose sides and have a $verb ball tournament.";

//inserting form info into db
$query = "INSERT INTO my_game (noun, verb, adjective, body_part, food_item) " .
  "VALUES ('$noun', '$verb', '$adjective', '$body_part', '$food_item')";

 //get query result from db  
$result = mysqli_query($dbc, $query)
        or die('Error querying database.');

if(empty($noun) || empty($verb) || empty($adjective) || empty($body_part) || empty($food_item)) {
  echo "You have not filled in all of the fields.Please go back and try again.";
}

$query2 = "SELECT * FROM my_game WHERE id ORDER BY desc";

  //while loop grabs name from array       
while($row = mysqli_fetch_array($query2)) {
    $noun = $row['noun'];
    $verb = $row['verb'];
    $adjective = $row['adjective'];
    $body_part = $row['body_part'];
    $food_item = $row['food_item'];    
    $full_story = "Here are some things to do at recess." 
                  "Start a game of touch $body_part-ball." 
                  "Put a $noun in someones lunch." 
                  "Start a $food_item fight in the school $adjective room." 
                  "Choose sides and have a $verb ball tournament.";

    //outputs story       
    echo $full_story;

}

//close connection 
mysqli_close($dbc);

?>

You are not executing the query before trying to fetch. The query is just a string in $query2.

You need to execute the query by calling mysqli->query

Since you already did this above it looks like you just missed it all together on the second query by accident. ( I've done this before).

After this line

$query2 = "SELECT * FROM my_game WHERE id ORDER BY desc";

You can do something like

 //get query result from db  
$result2 = mysqli_query($dbc, $query2)
        or die('Error querying database.');

and change this accordingly

while($row = mysqli_fetch_array($result2)) {