I am writing a madlib in php, saving it to a db using mysql, then trying to pull out each new story in descending order -
i not sure how story out of db, getting error:
warning: mysqli_fetch_array() expects parameter 1 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 db $dbc = mysqli_connect('localhost', 'root', '', 'project1') or die('error connecting mysql server.'); //creating variables $noun = $_post['noun']; $verb = $_post['verb']; $adjective = $_post['adjective']; $body_part = $_post['bodypart']; $food_item = $_post['fooditem']; $full_story = "here things @ recess." "start game of touch $body_part-ball." "put $noun in someones lunch." "start $food_item fight in school $adjective room." "choose sides , have $verb ball tournament."; //inserting form info db $query = "insert my_game (noun, verb, adjective, body_part, food_item) " . "values ('$noun', '$verb', '$adjective', '$body_part', '$food_item')"; //get query result 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 of fields.please go , try again."; } $query2 = "select * my_game id order desc"; //while loop grabs name 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 things @ recess." "start game of touch $body_part-ball." "put $noun in someones lunch." "start $food_item fight in school $adjective room." "choose sides , have $verb ball tournament."; //outputs story echo $full_story; } //close connection mysqli_close($dbc); ?>
you not executing query before trying fetch. query string in $query2
.
you need execute query calling mysqli->query
since did above looks missed on second query accident. ( i've done before).
after line
$query2 = "select * my_game id order desc";
you can like
//get query result db $result2 = mysqli_query($dbc, $query2) or die('error querying database.');
and change accordingly
while($row = mysqli_fetch_array($result2)) {
Comments
Post a Comment