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);
?>