php - Running an INSERT query inside an If statement -
i wondering if possible run insert query if answer correct, have tried multiple types of queries creating new stmt , array , inserting them database if answer if correct, basic understanding of how works, may missing something? not getting errors returned, getting echo statement returned.
note : know trying insert questionid multiple times put data database. updated correct fields.
can enlighten me on whats issue :
<?php // establishing mysqli connection require_once('connection-test.php'); $mysqli = new mysqli($host,$username,$password,$database); if($mysqli -> connect_error)die($mysqli->connect_error); $questionid = $_post['id']; $useranswer = $_post['answer']; $query = "select answers answers questionid=?"; $statement = $mysqli->prepare($query); $statement ->bind_param('i', $questionid); $statement->execute(); $statement->bind_result($answer); while($statement->fetch()){ if($answer != $useranswer){ echo "wrong"; //return previous page }else{ echo "correct"; mysqli_query($mysqli,"insert submissions (submissionsid,teamid,questionid,answer) values ($questionid,$questionid,$questionid,$useranswer)"); } } $statement->close(); ?>
turns out had free_result()before run mysqli statement
Comments
Post a Comment